blob: e28feccc07fe3ab0c2f1bb5537d4f2777afc2d83 [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);
Harald Welted71d5962024-03-27 19:17:19 +0100983 f_hnbap_hnb_register(0);
984 f_hnbap_hnb_register(1, 0, expect_reject := true);
Daniel Willmannc79679a2022-08-23 17:48:39 +0200985 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
986 f_shutdown_helper();
987}
988
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200989/* Try to register the same HNB in the same connection already established, aka
990 * duplicate HNB Register Request. It should be accepted and new configuration
991 * applied. TS 25.469 8.2.4 */
992testcase TC_hnb_register_duplicate_reuse_sctp_assoc() runs on test_CT {
993 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200994 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +0100995 f_hnbap_hnb_register(0);
996 f_hnbap_hnb_register(0);
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200997 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
998 f_shutdown_helper();
999}
1000
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02001001/* Drop HNBAP conn (HNBAP DEREG) and reconnect it (HNBAP REG) using same SCTP association.
1002 * Related: OS#5676, SYS#6113 */
1003testcase TC_hnb_reregister_reuse_sctp_assoc() runs on test_CT {
1004 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +02001005 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +01001006 f_hnbap_hnb_register(0);
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02001007 HNBAP[0].send(ts_HNBAP_HNBDe_Register(ts_HnbapCause(unspecified)));
Harald Welted71d5962024-03-27 19:17:19 +01001008 f_hnbap_hnb_register(0);
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02001009 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
1010 f_shutdown_helper();
1011}
1012
Harald Welteaf3e2162024-03-27 21:54:20 +01001013/* regular UE registration */
1014testcase TC_ue_register() runs on test_CT {
1015 var UE_Identity ue_id := { iMSI := imsi_hex2oct(f_gen_imsi(1)) };
1016 g_num_hnbs := 1;
1017 f_init(start_hnb := true);
1018 f_hnbap_ue_register(0, ue_id);
1019 f_shutdown_helper();
1020}
1021
Harald Weltef60044d2024-04-04 00:54:34 +02001022/* regular UE registration (UE Identity: TMSI+LAI) */
1023testcase TC_ue_register_tmsi_lai() runs on test_CT {
1024 var UE_Identity ue_id := { tMSILAI := { tMSI := oct2bit(f_gen_tmsi(0)),
1025 lAI := { pLMNID := '00F110'O, lAC := '2342'O }
1026 }
1027 };
1028 g_num_hnbs := 1;
1029 f_init(start_hnb := true);
1030 f_hnbap_ue_register(0, ue_id);
1031 f_shutdown_helper();
1032}
1033
1034
Harald Welteaf3e2162024-03-27 21:54:20 +01001035/* UE registration from unregistered HNB */
1036testcase TC_ue_register_before_hnb_register() runs on test_CT {
1037 var UE_Identity ue_id := { iMSI := imsi_hex2oct(f_gen_imsi(1)) };
1038 g_num_hnbs := 1;
1039 f_init(start_hnb := false);
1040 f_hnbap_ue_register(0, ue_id, expect_reject := true);
1041 f_shutdown_helper();
1042}
1043
Daniel Willmann19b8d902022-01-05 09:12:34 +01001044/***********************************************************************
1045 * RUA / RANAP Testing
1046 ***********************************************************************/
1047
Neels Hofmeyr7a48df12023-04-20 20:43:43 +02001048/* Translate from {msc,sgsn}x{0..n} to the proper index to use in g_cn[].
1049 * g_cn[] stores CN links, MSCs and SGSNs in the same array.
1050 * For example, for 'sgsn 23', use g_cn[ f_cn_idx(ps_domain := true, cn_nr := 23) ].
1051 *
1052 * Note the naming:
1053 * cn_nr is the number used in the cfg file, as in 'msc 0'.
1054 * cn_idx is the array index in g_cn[].
1055 */
1056private function f_cn_idx(boolean ps_domain, integer cn_nr := 0) return integer
1057{
1058 if (ps_domain) {
1059 return FIRST_SGSN_IDX + cn_nr;
1060 }
1061 return FIRST_MSC_IDX + cn_nr;
1062}
1063
Daniel Willmann19b8d902022-01-05 09:12:34 +01001064private template (value) TestHdlrParams
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001065t_pars(integer imsi_suffix, boolean ps_domain := false, integer hnb_idx := 0,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +02001066 boolean expect_separate_sccp_cr := false, integer tx_sccp_cr_data_len := 0,
Harald Welte18188342024-04-04 01:36:56 +02001067 integer cn_nr := 0, template (value) RANAP_IEs.Cause rab_rel_cause := ts_RanapCause_nas_normal) := {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001068 hnb_idx := hnb_idx,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +02001069 cn_idx := f_cn_idx(ps_domain, cn_nr),
Daniel Willmann19b8d902022-01-05 09:12:34 +01001070 imsi := f_gen_imsi(imsi_suffix),
1071 ps_domain := ps_domain,
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001072 mgcp_pars := t_MgcpParams,
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001073 hnb := omit, /* filled in later */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001074 expect_separate_sccp_cr := expect_separate_sccp_cr,
1075 tx_sccp_cr_data_len := tx_sccp_cr_data_len,
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02001076 pfcp_local_addr := mp_pfcp_ip_local,
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02001077 nas_pdu := omit,
1078 sccp_addr_msc := omit,
Harald Welte0d4a8432024-04-04 01:12:11 +02001079 sccp_addr_hnbgw := omit,
1080 rab_rel_cause := rab_rel_cause
Daniel Willmann19b8d902022-01-05 09:12:34 +01001081}
1082
1083/* Create an Iuh connection; send InitialUE; expect it to appear on new SCCP conenction */
1084friend function f_tc_initial_ue(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1085 f_init_handler(pars);
1086 var RANAP_PDU tx := f_build_initial_ue(g_pars);
1087 f_iuh2iu_connect(tx);
1088}
1089testcase TC_ranap_cs_initial_ue() runs on test_CT {
1090 var ConnHdlr vc_conn;
1091
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001092 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001093 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001094
1095 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue), t_pars(1));
1096 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001097
1098 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001099}
1100testcase TC_ranap_ps_initial_ue() runs on test_CT {
1101 var ConnHdlr vc_conn;
1102
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001103 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001104 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001105
1106 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue), t_pars(2, true));
1107 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001108
1109 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001110}
1111
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001112private function f_vty_set_sccp_max_optional_data(TELNETasp_PT pt, integer val := -1)
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001113{
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001114 var charstring valstr;
1115 if (val < 0) {
1116 valstr := "standard";
1117 } else {
1118 valstr := int2str(val);
1119 }
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001120 f_vty_enter_config(pt);
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001121 f_vty_transceive(pt, "cs7 instance 0");
1122 f_vty_transceive(pt, "sccp max-optional-data " & valstr);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001123 f_vty_transceive(pt, "end");
1124}
1125
1126testcase TC_ranap_cs_initial_ue_empty_cr() runs on test_CT {
1127 var ConnHdlr vc_conn;
1128
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001129 g_num_hnbs := 1;
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001130 f_init();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001131
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001132 f_vty_set_sccp_max_optional_data(HNBGWVTY, 0);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001133
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001134 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 +02001135 vc_conn.done;
1136
1137 /* reset */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001138 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001139
1140 f_shutdown_helper();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001141}
1142testcase TC_ranap_ps_initial_ue_empty_cr() runs on test_CT {
1143 var ConnHdlr vc_conn;
1144
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001145 g_num_hnbs := 1;
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001146 f_init();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001147
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001148 f_vty_set_sccp_max_optional_data(HNBGWVTY, 0);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001149
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001150 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 +02001151 vc_conn.done;
1152
1153 /* reset */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001154 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001155
1156 f_shutdown_helper();
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001157}
1158
1159type record Testdata_CR_Limit {
1160 integer data_len,
1161 integer max_optional_data,
1162 boolean expect_separate_sccp_cr
1163};
1164type record of Testdata_CR_Limit Testdata_CR_Limits;
1165
1166testcase TC_sccp_cr_limit() runs on test_CT {
1167 g_num_hnbs := 1;
1168 f_init();
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001169
1170 const Testdata_CR_Limits tests := {
1171 { data_len := 130, max_optional_data := -1, expect_separate_sccp_cr := false },
1172 { data_len := 131, max_optional_data := -1, expect_separate_sccp_cr := true },
1173
1174 { data_len := 100, max_optional_data := 100, expect_separate_sccp_cr := false },
1175 { data_len := 101, max_optional_data := 100, expect_separate_sccp_cr := true },
1176
1177 { data_len := 200, max_optional_data := 200, expect_separate_sccp_cr := false },
1178 { data_len := 201, max_optional_data := 200, expect_separate_sccp_cr := true }
1179 };
1180
1181 var integer csps;
1182 for (csps := 0; csps < 2; csps := csps + 1) {
1183 var boolean ps_domain := (csps > 0);
1184
1185 var integer i;
1186 for (i := 0; i < lengthof(tests); i := i + 1) {
1187 var Testdata_CR_Limit t := tests[i];
1188 f_logp(HNBGWVTY,
1189 "TEST PART TC_sccp_cr_limit ps_domain=" & f_bool2str(ps_domain)
1190 & " data_len=" & int2str(t.data_len)
1191 & " max_optional_data=" & int2str(t.max_optional_data)
1192 & " expect_separate_sccp_cr=" & f_bool2str(t.expect_separate_sccp_cr)
1193 );
1194
1195 f_vty_set_sccp_max_optional_data(HNBGWVTY, t.max_optional_data);
1196 var ConnHdlr vc_conn;
1197 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue),
1198 t_pars(100 + i,
1199 ps_domain := ps_domain,
1200 expect_separate_sccp_cr := t.expect_separate_sccp_cr,
1201 tx_sccp_cr_data_len := t.data_len));
1202 vc_conn.done;
1203 }
1204 }
1205
1206 /* reset */
1207 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001208
1209 f_shutdown_helper();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001210}
1211
Daniel Willmann19b8d902022-01-05 09:12:34 +01001212/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1213 * Return true when an OK reply was sent, false otherwise.
1214 * Count occurrence of Osmux, include Osmux parameters in the reply if necessary. */
1215function f_handle_crcx(inout MgcpParameters pars, MgcpCommand mgcp_cmd) return template MgcpResponse {
Pau Espin Pedrol264679f2023-11-29 15:52:00 +01001216 var MgwResponse conn := pars.mgw_conn_ran;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001217 if (pars.got_crcx_count > 0) {
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001218 conn := pars.mgw_conn_cn;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001219 }
1220 pars.got_crcx_count := pars.got_crcx_count + 1;
1221
1222 var MgcpMessage mgcp_msg := {
1223 command := mgcp_cmd
1224 }
1225 var template MgcpResponse mgcp_resp;
1226 var MgcpOsmuxCID osmux_cid;
1227 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1228 if (ispresent(pars.mgcp_call_id)) {
1229 if (pars.mgcp_call_id != call_id) {
1230 setverdict(fail, "CRCX contained unexpected call id. Expected:", pars.mgcp_call_id, " got:", call_id);
1231 mtc.stop;
1232 }
1233 } else {
1234 pars.mgcp_call_id := call_id;
1235 }
1236
1237 /* When the endpoint contains a wildcard we keep the endpoint
1238 * identifier we have set up in pars. Otherwise we use the
1239 * endpoint name that the call agent has supplied */
1240 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1241 pars.mgcp_ep := mgcp_cmd.line.ep;
1242 }
1243
1244 if (conn.resp == -1) {
1245 /* Reply with rror */
1246 var MgcpResponse mgcp_rsp := {
1247 line := {
1248 code := "542",
1249 trans_id := mgcp_cmd.line.trans_id,
1250 string := "FORCED_FAIL"
1251 },
1252 sdp := omit
1253
1254 }
1255 var MgcpParameter mgcp_rsp_param := {
1256 code := "Z",
1257 val := pars.mgcp_ep
1258 };
1259 mgcp_rsp.params[0] := mgcp_rsp_param;
1260 return mgcp_rsp;
1261 }
1262
1263 if (conn.resp == 0) {
1264 /* Do not reply at all */
1265 return omit;
1266 }
1267
1268 if (conn.resp != 1) {
1269 setverdict(fail, "Unexpected value for pars.mgw_conn_*.resp, expect -1, 0 or 1");
1270 mtc.stop;
1271 }
1272
1273 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1274 hex2str(pars.mgcp_call_id), "42",
1275 conn.mgw_rtp_port,
1276 { int2str(pars.rtp_payload_type) },
1277 { valueof(ts_SDP_rtpmap(pars.rtp_payload_type,
1278 pars.rtp_sdp_format)),
1279 valueof(ts_SDP_ptime(20)) }));
1280
1281 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1282 if (not pars.use_osmux) {
1283 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1284 mtc.stop;
1285 }
1286 pars.got_osmux_count := pars.got_osmux_count + 1;
1287 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1288 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1289 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1290 if (osmux_cid != -1) {
1291 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1292 mtc.stop;
1293 }
1294
1295 osmux_cid := 0;
1296 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1297 } else {
1298 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1299 }
1300
1301 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(pars.mgcp_ep));
1302
1303 return mgcp_resp;
1304}
1305
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001306friend function f_create_rab(inout MgcpParameters pars) runs on ConnHdlr {
1307 f_rab_ass_req(pars);
1308 f_rab_ass_resp(pars);
1309}
1310
1311friend function f_rab_ass_req(inout MgcpParameters pars) runs on ConnHdlr {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001312 var MgcpCommand mgcp_cmd;
1313 var RANAP_PDU tx;
1314 var template RAB_SetupOrModifyList rab_sml;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001315 timer T := 5.0;
1316
1317 /* Send RAB Assignment Request */
1318 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));
1319 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1320 BSSAP.send(tx);
1321 T.start;
1322
1323 /* Handle MGCP CRCX */
1324 alt {
1325 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1326 log("CRCX1", mgcp_cmd);
1327 var template MgcpResponse mgcp_rsp := f_handle_crcx(pars, mgcp_cmd);
1328 MGCP.send(valueof(mgcp_rsp));
1329 }
1330 [] T.timeout {
1331 setverdict(fail, "Timeout waiting for MGCP");
1332 }
1333 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001334 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001335
1336 /* Expect RAB Assignment Request with IP/port from CRCX ACK via Iuh */
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001337 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 +01001338 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1339
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001340 f_rua_expect(tx);
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001341}
1342
1343friend function f_rab_ass_resp(inout MgcpParameters pars) runs on ConnHdlr {
1344 var MgcpCommand mgcp_cmd;
1345 var RANAP_PDU tx;
1346 var template RAB_SetupOrModifiedList rab_smdl;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001347
1348 /* Send back RAB Assignment Response via Iuh */
1349 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));
1350 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1351 RUA.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001352
1353 interleave {
1354 /* Expect MDCX with IP/port from RAB Assignment Response */
1355 [] 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 +01001356 var HostName mgw_rtp_ip;
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001357 var boolean exp_rua_rab_reass := false;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001358 log("MDCX1", mgcp_cmd);
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001359 if (ispresent(pars.mgw_conn_ran.mgw_rtp_ip_mdcx)) {
1360 mgw_rtp_ip := pars.mgw_conn_ran.mgw_rtp_ip_mdcx;
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001361 if (pars.mgw_conn_ran.mgw_rtp_ip != pars.mgw_conn_ran.mgw_rtp_ip_mdcx) {
1362 exp_rua_rab_reass := true;
1363 }
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001364 } else {
1365 mgw_rtp_ip := pars.mgw_conn_ran.mgw_rtp_ip;
1366 }
1367
Daniel Willmann19b8d902022-01-05 09:12:34 +01001368 /* Verify SDP of MDCX */
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001369 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 +01001370 { 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 +01001371 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 +01001372 MGCP.send(valueof(mgcp_rsp));
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001373
1374 /* If IP address changed, we expect HNBGW to Modify the RAB through RAB-Ass-Req: */
1375 if (exp_rua_rab_reass) {
1376 var template RAB_SetupOrModifyList rab_sml;
1377 /* Expect RAB Assignment Request with IP/port from MDCX ACK via Iuh */
1378 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));
1379 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1380
1381 f_rua_expect(tx);
1382 /* Send back RAB Assignment Response via Iuh */
1383 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));
1384 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1385 RUA.send(tx);
1386 /* This shouldn't trigger any MGCP, since nothing changed on the HNB IP side. Continue below. */
1387 }
Daniel Willmann19b8d902022-01-05 09:12:34 +01001388 }
1389 /* Handle CRCX for second leg of endpoint, answer with IP/port */
1390 [] MGCP.receive(tr_CRCX(pars.mgcp_ep, tr_SDP(pars.cn_rtp_ip, pars.cn_rtp_port))) -> value mgcp_cmd {
1391 log("CRCX2", mgcp_cmd);
1392 /* Verify SDP of CRCX */
1393 var template MgcpResponse mgcp_rsp := f_handle_crcx(pars, mgcp_cmd);
1394 MGCP.send(valueof(mgcp_rsp));
1395 }
1396 }
1397
1398 /* Expect RAB Assignment Response with IP/port from second CRCX ACK */
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001399 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 +01001400 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1401
Neels Hofmeyrdc416c92023-03-09 02:47:50 +01001402 f_bssap_expect(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001403}
1404
1405private altstep as_mgcp_dlcx(inout TestHdlrParams pars) runs on ConnHdlr {
1406 var MgcpCommand mgcp_cmd;
1407
1408 [] MGCP.receive(tr_DLCX(pars.mgcp_pars.mgcp_ep)) -> value mgcp_cmd {
1409 log("DLCX", mgcp_cmd);
1410 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1411 pars.mgcp_pars.got_dlcx_count := pars.mgcp_pars.got_dlcx_count + 1;
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001412 if (pars.mgcp_pars.got_dlcx_count != pars.mgcp_pars.got_crcx_count) {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001413 repeat;
1414 }
1415 setverdict(pass);
1416 }
1417}
1418
1419friend function f_tc_rab_assignment(charstring id, TestHdlrParams pars) runs on ConnHdlr {
Harald Welte904b5f12024-04-04 02:47:30 +02001420 const charstring hnb0_ctr_prefix := "TTCN3.hnb.001-01-L2342-R0-S55-C1.";
Daniel Willmann19b8d902022-01-05 09:12:34 +01001421 var MgcpCommand mgcp_cmd;
1422 var RANAP_PDU tx;
1423 timer T := 5.0;
1424
1425 f_init_handler(pars);
1426 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1427
Harald Welte904b5f12024-04-04 02:47:30 +02001428 f_statsd_reset();
1429
Daniel Willmann19b8d902022-01-05 09:12:34 +01001430 tx := f_build_initial_ue(g_pars);
1431 f_iuh2iu_connect(tx);
1432
Harald Welte904b5f12024-04-04 02:47:30 +02001433 /* Expect stats to be 0 */
1434 var StatsDExpects expect := {
1435 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.req", mtype := "c", min := 0, max := 0},
1436 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.cnf", mtype := "c", min := 0, max := 0},
1437 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.fail", mtype := "c", min := 0, max := 0}
1438 };
1439 f_statsd_expect(expect);
1440
Daniel Willmann19b8d902022-01-05 09:12:34 +01001441 f_create_rab(pars.mgcp_pars);
1442
Harald Welte904b5f12024-04-04 02:47:30 +02001443 expect := {
1444 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.req", mtype := "c", min := 1, max := 1},
1445 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.cnf", mtype := "c", min := 1, max := 1},
1446 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.fail", mtype := "c", min := 0, max := 0}
1447 };
1448 f_statsd_expect(expect);
1449
Daniel Willmann19b8d902022-01-05 09:12:34 +01001450 /* Send Iu Release */
Harald Welte0d4a8432024-04-04 01:12:11 +02001451 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Daniel Willmann19b8d902022-01-05 09:12:34 +01001452 f_iu2iuh(tx);
1453
1454 T.start;
1455 alt {
1456 [] as_mgcp_dlcx(pars) {}
1457 [] T.timeout {
1458 setverdict(fail, "Timeout waiting for DLCX");
1459 }
1460 }
1461
1462 tx := valueof(ts_RANAP_IuReleaseComplete());
1463 f_iuh2iu(tx);
1464}
1465
1466testcase TC_rab_assignment() runs on test_CT {
1467 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001468 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001469 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001470
1471 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assignment), t_pars(3));
1472 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001473
1474 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001475}
1476
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001477friend function f_tc_rab_assign_fail(charstring id, TestHdlrParams pars) runs on ConnHdlr {
Harald Welte904b5f12024-04-04 02:47:30 +02001478 const charstring hnb0_ctr_prefix := "TTCN3.hnb.001-01-L2342-R0-S55-C1.";
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001479 var MgcpCommand mgcp_cmd;
1480 var RANAP_PDU tx;
1481 timer T := 5.0;
1482
1483 f_init_handler(pars);
1484 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1485
Harald Welte904b5f12024-04-04 02:47:30 +02001486 f_statsd_reset();
1487
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001488 tx := f_build_initial_ue(g_pars);
1489 f_iuh2iu_connect(tx);
1490
Harald Welte904b5f12024-04-04 02:47:30 +02001491 /* Expect stats to be 0 */
1492 var StatsDExpects expect := {
1493 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.req", mtype := "c", min := 0, max := 0},
1494 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.cnf", mtype := "c", min := 0, max := 0},
1495 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.fail", mtype := "c", min := 0, max := 0}
1496 };
1497 f_statsd_expect(expect);
1498
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001499 f_rab_ass_req(pars.mgcp_pars);
1500
1501 /* Send RAB failed list in response */
Harald Welte0d4a8432024-04-04 01:12:11 +02001502 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 +01001503 f_iuh2iu(tx);
1504
Harald Welte904b5f12024-04-04 02:47:30 +02001505 expect := {
1506 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.req", mtype := "c", min := 1, max := 1},
1507 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.cnf", mtype := "c", min := 0, max := 0},
1508 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.fail", mtype := "c", min := 1, max := 1}
1509 };
1510 f_statsd_expect(expect);
1511
1512
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001513 T.start;
1514 alt {
1515 [] as_mgcp_dlcx(pars) {}
1516 [] T.timeout {
1517 setverdict(fail, "Timeout waiting for DLCX");
1518 }
1519 }
1520}
1521
1522testcase TC_rab_assign_fail() runs on test_CT {
1523 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001524 g_num_hnbs := 1;
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001525 f_init();
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001526
Harald Welte18188342024-04-04 01:36:56 +02001527 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 +01001528 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001529
1530 f_shutdown_helper();
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001531}
1532
Daniel Willmann19b8d902022-01-05 09:12:34 +01001533friend function f_tc_rab_release(charstring id, TestHdlrParams pars) runs on ConnHdlr {
Harald Welte904b5f12024-04-04 02:47:30 +02001534 const charstring hnb0_ctr_prefix := "TTCN3.hnb.001-01-L2342-R0-S55-C1.";
Daniel Willmann19b8d902022-01-05 09:12:34 +01001535 var MgcpCommand mgcp_cmd;
1536 var RANAP_PDU tx;
1537 timer T := 15.0;
1538
1539 f_init_handler(pars);
1540 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1541
Harald Welte904b5f12024-04-04 02:47:30 +02001542 f_statsd_reset();
1543
Daniel Willmann19b8d902022-01-05 09:12:34 +01001544 tx := f_build_initial_ue(g_pars);
1545 f_iuh2iu_connect(tx);
1546
1547 f_create_rab(pars.mgcp_pars);
1548
Harald Welte904b5f12024-04-04 02:47:30 +02001549 var charstring ctr_name;
1550 if (pars.rab_rel_cause == valueof(ts_RanapCause_nas_normal)) {
1551 ctr_name := "ranap.cs.rab_rel.req.normal";
1552 } else {
1553 ctr_name := "ranap.cs.rab_rel.req.abnormal";
1554 }
1555
1556 /* Expect stats to be 0 */
1557 var StatsDExpects expect := {
1558 {name := hnb0_ctr_prefix & ctr_name, mtype := "c", min := 0, max := 0}
1559 };
1560 f_statsd_expect(expect);
1561
Daniel Willmann19b8d902022-01-05 09:12:34 +01001562 /* Send RAB Release */
Harald Welte0d4a8432024-04-04 01:12:11 +02001563 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 +01001564 BSSAP.send(tx);
1565
Harald Welte904b5f12024-04-04 02:47:30 +02001566 expect := {
1567 {name := hnb0_ctr_prefix & ctr_name, mtype := "c", min := 1, max := 1}
1568 };
1569 f_statsd_expect(expect);
1570
Daniel Willmann19b8d902022-01-05 09:12:34 +01001571 T.start;
1572
1573 alt {
1574 [] as_mgcp_dlcx(pars) {}
1575 [] T.timeout {
1576 setverdict(fail, "Timeout waiting for DLCX");
1577 }
1578 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001579 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001580
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001581 f_rua_expect(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001582}
1583
Harald Weltef95ab2d2024-04-04 01:32:20 +02001584/* RAB release with Cause NAS/Normal (successful/orderly release) */
Daniel Willmann19b8d902022-01-05 09:12:34 +01001585testcase TC_rab_release() runs on test_CT {
1586 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001587 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001588 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001589
1590 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_release), t_pars(5));
1591 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001592
1593 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001594}
1595
Harald Weltef95ab2d2024-04-04 01:32:20 +02001596/* RAB release with Cause abnormal */
1597testcase TC_rab_release_abnormal() runs on test_CT {
1598 var ConnHdlr vc_conn;
1599 g_num_hnbs := 1;
1600 f_init();
1601
Harald Welte7a9e7962024-04-04 02:46:45 +02001602 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_release),
1603 t_pars(8, rab_rel_cause := ts_RanapCause_radio_conn_lost));
Harald Weltef95ab2d2024-04-04 01:32:20 +02001604 vc_conn.done;
1605
1606 f_shutdown_helper();
1607}
1608
Daniel Willmann37c877f2022-02-22 16:47:06 +01001609friend function f_tc_rab_assign_mgcp_to(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1610 var MgcpCommand mgcp_cmd;
1611 var RANAP_PDU tx;
1612 var template RAB_SetupOrModifyList rab_sml;
1613 timer T := 15.0;
1614
1615 T.start;
1616 f_init_handler(pars);
1617 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1618
1619 tx := f_build_initial_ue(g_pars);
1620 f_iuh2iu_connect(tx);
1621
1622
1623 /* Send RAB Assignment Request */
1624 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));
1625 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1626 BSSAP.send(tx);
1627
1628 /* Ignore MGCP CRCX */
1629 alt {
1630 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1631 log("Ignoreing CRCX1", mgcp_cmd);
1632 repeat;
1633 }
1634 [] BSSAP.receive(tr_RANAP_IuReleaseRequest(?)) { }
1635 [] T.timeout {
1636 setverdict(fail, "Timeout waiting for IuRelease");
1637 }
1638 }
1639
1640 /* Send Iu Release */
Harald Welte0d4a8432024-04-04 01:12:11 +02001641 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Daniel Willmann37c877f2022-02-22 16:47:06 +01001642 f_iu2iuh(tx);
1643
1644 tx := valueof(ts_RANAP_IuReleaseComplete());
1645 f_iuh2iu(tx);
1646}
1647
1648testcase TC_rab_assign_mgcp_to() runs on test_CT {
1649 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001650 g_num_hnbs := 1;
Daniel Willmann37c877f2022-02-22 16:47:06 +01001651 f_init();
Daniel Willmann37c877f2022-02-22 16:47:06 +01001652
1653 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assign_mgcp_to), t_pars(6));
1654 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001655
1656 f_shutdown_helper();
Daniel Willmann37c877f2022-02-22 16:47:06 +01001657}
1658
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001659/* Test case where IuUP IP address announced by HNB and updated through MDCX
1660 * makes MGW select a new local IuUP address. HNBGW is expected to update the HNB
1661 * through RAB-Modify-Req. */
1662testcase TC_rab_assign_mgw_iuup_addr_chg() runs on test_CT {
1663 var ConnHdlr vc_conn;
1664 g_num_hnbs := 1;
1665 f_init();
1666 var template (value) TestHdlrParams pars := t_pars(3);
1667 /* Emulate change of local IuUP IP address after rx MDCX: */
1668 pars.mgcp_pars.mgw_conn_ran.mgw_rtp_ip_mdcx := "127.3.2.1";
1669
1670 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assignment), pars);
1671 vc_conn.done;
1672
1673 f_shutdown_helper();
1674}
1675
Daniel Willmann19b8d902022-01-05 09:12:34 +01001676/* Create an Iuh connection; send InitialUE; transceive data both directions */
1677friend function f_tc_ranap_bidir(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1678 f_init_handler(pars);
1679
1680 /* HNB -> MSC: InitialUE */
1681 f_iuh2iu_connect(f_build_initial_ue(g_pars));
1682
1683 /* MSC <- HNB: DirectTransfer */
1684 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1685 /* MSC -> HNB: DirectTransfer */
1686 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1687
1688 /* HNB <- MSC: CommonID */
1689 f_iu2iuh(ts_RANAP_CommonId(hex2oct(pars.imsi)));
1690}
1691testcase TC_ranap_cs_bidir() runs on test_CT {
1692 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001693 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001694 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001695
1696 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_bidir), t_pars(3));
1697 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001698
1699 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001700}
1701testcase TC_ranap_ps_bidir() runs on test_CT {
1702 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001703 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001704 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001705
1706 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_bidir), t_pars(4, true));
1707 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001708
1709 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001710}
1711
1712
1713private function f_tc_ranap_mo_disconnect(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1714 f_init_handler(pars);
1715
1716 /* HNB -> MSC: InitialUE */
1717 f_iuh2iu_connect(f_build_initial_ue(g_pars));
1718
1719 /* MSC <- HNB: DirectTransfer */
1720 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1721 /* MSC -> HNB: DirectTransfer */
1722 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1723
1724 /* MSC <- HNB: RUA disconnect */
1725 f_iuh2iu_disconnect(ts_RANAP_IuReleaseComplete, RUA_IEs.Cause:{misc:=processing_overload});
1726}
1727testcase TC_ranap_cs_mo_disconnect() runs on test_CT {
1728 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001729 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001730 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001731
1732 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_mo_disconnect), t_pars(5));
1733 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001734
1735 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001736}
1737testcase TC_ranap_ps_mo_disconnect() runs on test_CT {
1738 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001739 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001740 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001741
1742 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_mo_disconnect), t_pars(6));
1743 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001744
1745 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001746}
1747
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001748type record FTeid {
1749 HostName addr,
1750 OCT4 teid
1751}
1752
1753type record FTeids {
1754 FTeid local,
1755 FTeid remote
1756}
Daniel Willmann19b8d902022-01-05 09:12:34 +01001757
1758
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001759/* 'local' and 'remote' refer to the GTP information from the UPF's point of view:
1760 * HNB UPF CN
1761 * access.remote <---> access.local | core.local <---> core.remote
1762 */
1763type record GtpParameters {
1764 FTeids core,
1765 FTeids access
1766}
1767
1768/* HNB UPF CN
1769 * access.remote <---> access.local | core.local <---> core.remote
1770 * 127.0.0.4 127.0.0.3 127.0.0.2 127.0.0.1
1771 * 0x44004400 0x30303030 0x22002200 0x10101010
1772 */
1773template GtpParameters t_GtpParameters := {
1774 core := {
1775 local := {
1776 addr := "127.0.0.2",
1777 teid := '22002200'O
1778 },
1779 remote := {
1780 addr := "127.0.0.1",
1781 teid := '10101010'O
1782 }
1783 },
1784 access := {
1785 local := {
1786 addr := "127.0.0.3",
1787 teid := '30303030'O
1788 },
1789 remote := {
1790 addr := "127.0.0.4",
1791 teid := '44004400'O
1792 }
1793 }
1794}
1795
Neels Hofmeyr65499282023-04-25 02:31:51 +02001796private 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 +01001797{
1798 var PDU_PFCP rx;
Neels Hofmeyr65499282023-04-25 02:31:51 +02001799 timer T := wait_time;
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001800 T.start;
1801 alt {
1802 [] PFCP.receive(exp_rx) -> value rx {
1803 setverdict(pass);
1804 }
1805 [] PFCP.receive(PDU_PFCP:?) {
1806 setverdict(fail, "Got an unexpected PFCP message, was waiting for ", exp_rx);
1807 mtc.stop;
1808 }
1809 [] T.timeout {
1810 setverdict(fail, "Timeout waiting for PFCP ", exp_rx);
1811 mtc.stop;
1812 }
1813 }
1814 T.stop;
1815 return rx;
1816}
1817
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001818friend function f_tc_ps_rab_assignment_with_pfcp(charstring id, TestHdlrParams pars) runs on ConnHdlr {
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001819 var RANAP_PDU tx;
1820 var RANAP_PDU rx;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001821
1822 f_init_handler(pars);
1823
1824 f_pfcp_register();
1825
1826 var PDU_PFCP m;
1827 var Node_ID upf_node_id := valueof(ts_PFCP_Node_ID_fqdn("\07osmocom\03org"));
1828
Neels Hofmeyr65499282023-04-25 02:31:51 +02001829 m := f_pfcp_expect(tr_PFCP_Assoc_Setup_Req(), wait_time := 15.0);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001830 PFCP.send(ts_PFCP_Assoc_Setup_Resp(m.sequence_number, upf_node_id,
1831 ts_PFCP_Cause(REQUEST_ACCEPTED), 1234));
1832
1833 tx := f_build_initial_ue(g_pars);
1834 f_iuh2iu_connect(tx);
1835
1836 var GtpParameters gtp_pars := valueof(t_GtpParameters);
1837 var template RAB_SetupOrModifyList rab_sml;
1838
1839 /* Send RAB Assignment Request */
1840 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.core.remote.addr), gtp_pars.core.remote.teid);
1841 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1842 BSSAP.send(tx);
1843
1844 /* Expect PFCP Session Establishment Request. */
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001845 m := f_pfcp_expect(tr_PFCP_Session_Est_Req());
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001846 var F_SEID hnbgw_f_seid := m.message_body.pfcp_session_establishment_request.CP_F_SEID;
1847 var PFCP_Session_Establishment_Request serq := m.message_body.pfcp_session_establishment_request;
1848
1849 /* Acting as UPF, invent a new PFCP SEID to send to HNBGW. Respond to the Session Establishment.
1850 * The PFCP response must have the same sequence_number as the request. */
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001851 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 +02001852 var template PDU_PFCP r := ts_PFCP_Session_Est_Resp(m.sequence_number, upf_node_id, hnbgw_f_seid.seid);
1853 r.message_body.pfcp_session_establishment_response := {
1854 offending_ie := omit,
1855 UP_F_SEID := up_f_seid,
1856 created_PDR_list := {
1857 ts_PFCP_Created_PDR(pdr_id := serq.create_PDR_list[0].grouped_ie.pdr_id,
1858 local_F_TEID := ts_PFCP_F_TEID_ipv4(gtp_pars.core.local.teid,
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001859 f_inet_addr(gtp_pars.core.local.addr))),
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001860 ts_PFCP_Created_PDR(pdr_id := serq.create_PDR_list[1].grouped_ie.pdr_id,
1861 local_F_TEID := ts_PFCP_F_TEID_ipv4(gtp_pars.access.local.teid,
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001862 f_inet_addr(gtp_pars.access.local.addr)))
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001863 },
1864 load_control_information := omit,
1865 overload_control_information := omit,
1866 node_list := omit,
1867 failed_rule_id := omit,
1868 created_traffic_endpoint_list := omit
1869 };
1870 PFCP.send(r);
1871
1872 /* Expect on Iuh: RAB Assignment Request with IP/port from PFCP Session Est Resp */
1873 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.local.addr),
1874 gtp_pars.access.local.teid);
1875 rx := valueof(ts_RANAP_RabAssReq(rab_sml));
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001876 f_rua_expect(rx);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001877
1878 /* Send back RAB Assignment Response via Iuh */
1879 var template RAB_SetupOrModifiedList rab_smdl;
1880 rab_smdl := ts_RAB_SMdL_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.remote.addr),
1881 gtp_pars.access.remote.teid);
1882 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1883 RUA.send(tx);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001884
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001885 m := f_pfcp_expect(tr_PFCP_Session_Mod_Req(up_f_seid.seid));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001886 r := ts_PFCP_Session_Mod_Resp(m.sequence_number, hnbgw_f_seid.seid);
1887 PFCP.send(r);
1888
1889 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 +01001890 f_bssap_expect(tr_RANAP_RabAssResp(rab_smdl));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001891
1892 f_sleep(2.0);
Harald Welte0d4a8432024-04-04 01:12:11 +02001893 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001894 f_iu2iuh(tx);
1895
1896 tx := valueof(ts_RANAP_IuReleaseComplete());
1897 f_iuh2iu(tx);
1898
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001899 m := f_pfcp_expect(tr_PFCP_Session_Del_Req(up_f_seid.seid));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001900 PFCP.send(ts_PFCP_Session_Del_Resp(m.sequence_number, hnbgw_f_seid.seid));
1901
1902 f_sleep(2.0);
1903}
1904
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001905testcase TC_ps_rab_assignment_with_pfcp() runs on test_CT {
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001906 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001907 g_num_hnbs := 1;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001908 f_init();
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001909 f_sleep(1.0);
1910
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001911 vc_conn := f_start_handler_with_pars(refers(f_tc_ps_rab_assignment_with_pfcp), t_pars(7, ps_domain := true));
1912 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001913
1914 f_shutdown_helper();
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001915}
1916
1917altstep as_disallow_pfcp() runs on ConnHdlr {
1918 [] PFCP.receive(PDU_PFCP:?) {
1919 setverdict(fail, "Received PFCP message, but no PFCP communication expected");
1920 mtc.stop;
1921 }
1922}
1923
1924friend function f_tc_ps_rab_assignment_without_pfcp(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1925 var RANAP_PDU tx;
1926 var RANAP_PDU rx;
1927 timer T := 5.0;
1928
1929 f_init_handler(pars);
1930
1931 f_pfcp_register();
1932 activate(as_disallow_pfcp());
1933
1934 tx := f_build_initial_ue(g_pars);
1935 f_iuh2iu_connect(tx);
1936
1937 var GtpParameters gtp_pars := valueof(t_GtpParameters);
1938 var template RAB_SetupOrModifyList rab_sml;
1939
1940 /* Send RAB Assignment Request */
1941 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.core.remote.addr), gtp_pars.core.remote.teid);
1942 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1943 BSSAP.send(tx);
1944
1945 /* Expect on Iuh: unmodified RAB Assignment Request */
1946 rx := valueof(ts_RANAP_RabAssReq(rab_sml));
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001947 f_rua_expect(rx);
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001948
1949 /* Send back RAB Assignment Response via Iuh */
1950 var template RAB_SetupOrModifiedList rab_smdl;
1951 rab_smdl := ts_RAB_SMdL_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.remote.addr),
1952 gtp_pars.access.remote.teid);
1953 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1954 RUA.send(tx);
1955
1956 /* Expect on IuPS: unmodified RAB Assignment Response */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +01001957 f_bssap_expect(tr_RANAP_RabAssResp(rab_smdl));
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001958
1959 f_sleep(2.0);
Harald Welte0d4a8432024-04-04 01:12:11 +02001960 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001961 f_iu2iuh(tx);
1962
1963 tx := valueof(ts_RANAP_IuReleaseComplete());
1964 f_iuh2iu(tx);
1965
1966 f_sleep(2.0);
1967}
1968
1969testcase TC_ps_rab_assignment_without_pfcp() runs on test_CT {
1970 var ConnHdlr vc_conn;
1971 f_init();
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001972 f_sleep(1.0);
1973
1974 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 +02001975 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001976
1977 f_shutdown_helper();
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001978}
Daniel Willmann19b8d902022-01-05 09:12:34 +01001979
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02001980/* Default list of counters for a 'cn' entity to test the cnpool feature. */
1981const CounterNameVals counternames_cnpool := {
1982 { "cnpool:subscr:new", 0 },
1983 { "cnpool:subscr:known", 0 },
1984 { "cnpool:subscr:reattach", 0 },
1985 { "cnpool:subscr:attach_lost", 0 },
1986 { "cnpool:subscr:paged", 0 }
1987};
1988private function f_ctrs_cn_init(boolean ps_domain, integer cn_count := 0,
1989 CounterNameVals counternames := counternames_cnpool) runs on test_CT {
1990 if (ps_domain) {
1991 g_ctr_cn_node_name := "sgsn";
1992 if (cn_count == 0) {
1993 cn_count := NUM_SGSN;
1994 }
1995 } else {
1996 g_ctr_cn_node_name := "msc";
1997 if (cn_count == 0) {
1998 cn_count := NUM_MSC;
1999 }
2000 }
2001 g_ctr_cn := f_counter_name_vals_get_n(IPA_CTRL, g_ctr_cn_node_name, cn_count, counternames);
2002 log("initial " & g_ctr_cn_node_name & " rate counters: ", g_ctr_cn);
2003}
2004
2005/* f_ctrs_cn_init();
2006 * f_do_thing(on_cn := 0);
2007 * f_do_thing(on_cn := 0);
2008 * f_do_other(on_cn := 1);
2009 * f_ctrs_cn_add(0, "thing", 2);
2010 * f_ctrs_cn_add(1, "other");
2011 * f_ctrs_cn_verify();
2012 */
2013private function f_ctrs_cn_verify() runs on test_CT {
2014 log("verifying", g_ctr_cn_node_name, " rate counters: ", g_ctr_cn);
2015 f_counter_name_vals_expect_n(IPA_CTRL, g_ctr_cn_node_name, g_ctr_cn);
2016}
2017
2018/* convenience: f_ctrs_cn_add() and f_ctrs_cn_verify() in one call.
2019 * f_ctrs_cn_init();
2020 * f_do_thing(on_cn := 0);
2021 * f_do_thing(on_cn := 0);
2022 * f_do_thing(on_cn := 0);
2023 * f_ctrs_cn_expect(0, "thing", 3);
2024 */
2025private function f_ctrs_cn_expect(integer cn_nr, charstring countername, integer val := 1) runs on test_CT {
2026 f_ctrs_cn_add(cn_nr, countername, val);
2027 f_ctrs_cn_verify();
2028}
2029
2030private function f_ctrs_cn_add(integer cn_nr, charstring countername, integer val := 1) runs on test_CT {
2031 f_counter_name_vals_list_add(g_ctr_cn, cn_nr, countername, val);
2032}
2033
2034private function f_perform_compl_l3(octetstring nas, boolean do_clear := true, boolean expect_iu_l3 := true)
2035runs on ConnHdlr {
2036 timer T := 10.0;
2037
2038 /* create an expect on the Iu side for the random NAS portion */
2039 if (g_pars.expect_separate_sccp_cr) {
2040 f_ran_register_sccp_cr_without_payload();
2041 } else {
2042 f_ran_register_exp(nas);
2043 }
2044
2045 /* send Connect via Iuh (creating a RUA connection) */
2046 var RANAP_PDU tx := f_build_initial_ue_with_nas(g_pars, nas);
2047 RUA.send(RUA_Conn_Req:{g_pars.ps_domain, tx});
2048
2049 if (expect_iu_l3) {
2050 /* Expect same message to arrive at CN */
2051 f_bssap_expect(tx);
2052 }
2053}
2054
2055private function f_tc_cnpool_compl_l3(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2056 f_init_handler(pars);
2057 f_perform_compl_l3(g_pars.nas_pdu);
2058}
2059
2060private function f_TC_cnpool_compl_l3(boolean ps_domain, octetstring nas_pdu, integer cn_nr,
2061 template (omit) charstring inc_countername := omit) runs on test_CT {
2062 var ConnHdlr vc_conn;
2063 var template (value) TestHdlrParams pars := t_pars(0, ps_domain := ps_domain, cn_nr := cn_nr);
2064 pars.nas_pdu := nas_pdu;
2065 log("XXX ", pars);
2066 vc_conn := f_start_handler_with_pars(refers(f_tc_cnpool_compl_l3), pars);
2067 vc_conn.done;
2068
2069 if (not istemplatekind(inc_countername, "omit")) {
2070 f_ctrs_cn_expect(cn_nr, valueof(inc_countername));
2071 }
2072}
2073
2074function f_TC_cnpool_compl_l3_list(boolean ps_domain, ro_octetstring compl3, Osmocom_Types.ro_integer cn_nrs,
2075 charstring inc_countername) runs on test_CT {
2076 var integer n := lengthof(compl3);
2077 if (n < lengthof(cn_nrs)) {
2078 n := lengthof(cn_nrs);
2079 }
2080 for (var integer i := 0; i < n; i := i + 1) {
2081 var integer cn_nr := cn_nrs[i mod lengthof(cn_nrs)];
2082 f_TC_cnpool_compl_l3(ps_domain, compl3[i mod lengthof(compl3)], cn_nr, inc_countername);
2083 }
2084}
2085
2086type enumerated Compl3Type {
2087 /* CS */
2088 LU,
2089 CMSERV,
2090 PAGRESP,
2091 IMSIDETACH,
2092
2093 /* PS */
2094 ATTACHREQ,
2095 RAUREQ,
2096 DETREQ
2097};
2098
2099private function f_gen_one_compl_l3(Compl3Type compl3type, template (value) MobileIdentityLV mi,
2100 integer ps_nri := -1
2101 ) return octetstring
2102{
2103 /* CS */
2104 if (compl3type == LU) {
2105 return enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(mi), '00F110'O)));
2106 }
2107 if (compl3type == CMSERV) {
2108 return enc_PDU_ML3_MS_NW(valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(mi))));
2109 }
2110 if (compl3type == PAGRESP) {
2111 return enc_PDU_ML3_MS_NW(valueof(ts_PAG_RESP(valueof(mi))));
2112 }
2113 if (compl3type == IMSIDETACH) {
2114 return enc_PDU_ML3_MS_NW(valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(mi))));
2115 }
2116
2117 /* PS */
2118 var template (omit) NetworkResourceIdentifierContainerTLV nri := omit;
2119 if (ps_nri >= 0) {
2120 nri := valueof(ts_GMM_NRI(ps_nri));
2121 }
2122
2123 if (compl3type == ATTACHREQ) {
2124 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_ATTACH_REQ(valueof(mi), f_RAI('001'H, '01'H, '2a2a'O, '17'O),
2125 nri := nri)));
2126 }
2127 if (compl3type == RAUREQ) {
2128 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_RAU_REQ(valueof(mi), GPRS_UPD_T_PERIODIC,
2129 f_RAI('001'H, '01'H, '2a2a'O, '17'O),
2130 nri := nri)));
2131 }
2132 if (compl3type == DETREQ) {
2133 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_DET_REQ_MO_mi(c_GMM_DTT_MO_GPRS, power_off := false,
2134 p_tmsi := valueof(ts_MI_TLV(mi.mobileIdentityV)))));
2135 }
2136
2137 setverdict(fail, "unknown complete layer 3 type");
2138 mtc.stop;
2139}
2140
2141type record of Compl3Type ro_Compl3Type;
2142type record of MobileIdentityLV ro_MobileIdentityLV;
2143type record of octetstring ro_octetstring;
2144
2145/* Generate a list of n Complete Layer 3 NAS PDUs,
2146 * rotating through the message kinds listed in 'types' and the mobile identities in mis.
2147 */
2148private function f_gen_compl_l3(ro_Compl3Type types, ro_MobileIdentityLV mis, integer n) return ro_octetstring
2149{
2150 var ro_octetstring res := {};
2151 for (var integer i := 0; i < n; i := i + 1) {
2152 var integer ti := i mod lengthof(types);
2153 var integer mi := i mod lengthof(mis);
2154 res[i] := f_gen_one_compl_l3(types[ti], mis[mi]);
2155 }
2156 return res;
2157}
2158
2159private function f_gen_mi_imsi(integer n) return MobileIdentityLV
2160{
2161 return valueof(ts_MI_IMSI_LV(f_gen_imsi(n)));
2162}
2163
2164private function f_gen_mi_imsis(integer n) return ro_MobileIdentityLV
2165{
2166 var ro_MobileIdentityLV mis := {};
2167 for (var integer i := 0; i < n; i := i + 1) {
2168 mis[i] := f_gen_mi_imsi(n);
2169 }
2170 return mis;
2171}
2172
2173function f_vty_set_roundrobin_next(TELNETasp_PT VTY, boolean ps_domain, integer cn_nr)
2174{
2175 var charstring msc_sgsn;
2176 if (ps_domain) {
2177 msc_sgsn := "sgsn";
2178 } else {
2179 msc_sgsn := "msc";
2180 }
2181 f_vty_transceive(VTY, "cnpool roundrobin next " & msc_sgsn & " " & int2str(cn_nr));
2182}
2183
2184private function f_gen_compl3_by_domain(boolean ps_domain, integer n, template (omit) ro_MobileIdentityLV mis := omit) return ro_octetstring{
2185 var ro_Compl3Type types;
2186 if (ps_domain) {
2187 types := { ATTACHREQ, RAUREQ, DETREQ };
2188 } else {
2189 types := { LU, CMSERV, PAGRESP, IMSIDETACH };
2190 }
2191 if (istemplatekind(mis, "omit")) {
2192 mis := f_gen_mi_imsis(n);
2193 }
2194 return f_gen_compl_l3(types, valueof(mis), n);
2195}
2196
2197/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
2198testcase TC_mscpool_L3Compl_on_1_cnlink() runs on test_CT {
2199 f_TC_cnpool_L3Compl_on_1_cnlink(ps_domain := false);
2200}
2201testcase TC_sgsnpool_L3Compl_on_1_cnlink() runs on test_CT {
2202 f_TC_cnpool_L3Compl_on_1_cnlink(ps_domain := true);
2203}
2204function f_TC_cnpool_L3Compl_on_1_cnlink(boolean ps_domain) runs on test_CT {
2205
2206 f_init();
2207
2208 f_ctrs_cn_init(ps_domain := ps_domain);
2209
2210 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 4);
2211 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {0, 0, 0, 0}, "cnpool:subscr:new");
2212
2213 f_shutdown_helper();
2214}
2215
2216/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
2217testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
2218 f_TC_cnpool_L3Complete_by_imsi_round_robin(ps_domain := false);
2219}
2220testcase TC_sgsnpool_L3Complete_no_nri_round_robin() runs on test_CT {
2221 f_TC_cnpool_L3Complete_by_imsi_round_robin(ps_domain := true);
2222}
2223function f_TC_cnpool_L3Complete_by_imsi_round_robin(boolean ps_domain) runs on test_CT {
2224
2225 f_init(nr_msc := 2, nr_sgsn := 2);
2226 f_sleep(1.0);
2227
2228 /* Control which MSC gets chosen next by the round-robin, otherwise
2229 * would be randomly affected by which other tests ran before this. */
2230 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2231
2232 f_ctrs_cn_init(ps_domain := ps_domain);
2233
2234 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2235
2236 f_TC_cnpool_compl_l3_list(ps_domain, compl3,
2237 /* Third Complete Layer 3 wraps back to msc 0 */
2238 cn_nrs := {0, 1, 0},
2239 inc_countername := "cnpool:subscr:new");
2240
2241 f_shutdown_helper();
2242}
2243
2244/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain a NULL-NRI (0, 1)
2245 * (configured in osmo-hnbgw.cfg). */
2246testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
2247 f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(ps_domain := false, nri_val := 0);
2248}
2249/* 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
2250 * than that. */
2251testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
2252 f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(ps_domain := false, nri_val := 1);
2253}
2254function f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(boolean ps_domain, integer nri_val) runs on test_CT {
2255
2256 f_init(nr_msc := 2, nr_sgsn := 2);
2257 f_sleep(1.0);
2258
2259 /* Control which MSC gets chosen next by the round-robin, otherwise
2260 * would be randomly affected by which other tests ran before this. */
2261 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2262
2263 f_ctrs_cn_init(ps_domain := ps_domain);
2264
2265 var ro_MobileIdentityLV mis := { valueof(ts_MI_TMSI_NRI_LV(nri_val)) };
2266 var ro_octetstring compl3;
2267 if (ps_domain) {
2268 compl3 := {
2269 f_gen_one_compl_l3(ATTACHREQ, mis[0], nri_val)
2270 };
2271 } else {
2272 compl3 := f_gen_compl_l3({LU}, mis, 1);
2273 }
2274
2275 f_TC_cnpool_compl_l3_list(ps_domain, compl3,
2276 /* The third Complete Layer 3 wraps back to msc 0 */
2277 {0, 1, 0},
2278 "cnpool:subscr:reattach");
2279 f_shutdown_helper();
2280}
2281
2282/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
2283 * assigned to any MSC (configured in osmo-hnbgw.cfg). */
2284testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
2285 f_TC_cnpool_L3Complete_by_tmsi_unassigned_nri_round_robin(ps_domain := false);
2286}
2287function f_TC_cnpool_L3Complete_by_tmsi_unassigned_nri_round_robin(boolean ps_domain) runs on test_CT {
2288
2289 f_init(nr_msc := 2, nr_sgsn := 2);
2290 f_sleep(1.0);
2291
2292 /* Control which MSC gets chosen next by the round-robin, otherwise
2293 * would be randomly affected by which other tests ran before this. */
2294 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2295
2296 f_ctrs_cn_init(ps_domain := ps_domain);
2297
2298 /* 3 NRIs that are not assigned to any MSC */
2299 var ro_MobileIdentityLV mis := {
2300 valueof(ts_MI_TMSI_NRI_LV(1000)),
2301 valueof(ts_MI_TMSI_NRI_LV(768)),
2302 valueof(ts_MI_TMSI_NRI_LV(819))
2303 };
2304
2305 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2306 f_TC_cnpool_compl_l3_list(ps_domain, compl3, { 0, 1, 0 }, "cnpool:subscr:new");
2307
2308 f_shutdown_helper();
2309}
2310
2311/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
2312 * assigned to a CN link that is currently not connected (configured in osmo-hnbgw.cfg). */
2313testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
2314 f_TC_cnpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin(ps_domain := false);
2315}
2316function f_TC_cnpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin(boolean ps_domain) runs on test_CT {
2317
2318 f_init(nr_msc := 2, nr_sgsn := 2);
2319 f_sleep(1.0);
2320
2321 /* Control which MSC gets chosen next by the round-robin, otherwise
2322 * would be randomly affected by which other tests ran before this. */
2323 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2324
2325 f_ctrs_cn_init(ps_domain := ps_domain);
2326
2327 /* 3 NRIs that are assigned to an unconnected MSC */
2328 var ro_MobileIdentityLV mis := {
2329 valueof(ts_MI_TMSI_NRI_LV(512)),
2330 valueof(ts_MI_TMSI_NRI_LV(767)),
2331 valueof(ts_MI_TMSI_NRI_LV(750))
2332 };
2333
2334 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2335
2336 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0);
2337 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2338 f_ctrs_cn_add(0, "cnpool:subscr:new");
2339 f_ctrs_cn_verify();
2340
2341 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 1);
2342 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2343 f_ctrs_cn_add(1, "cnpool:subscr:new");
2344 f_ctrs_cn_verify();
2345
2346 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 0);
2347 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2348 f_ctrs_cn_add(0, "cnpool:subscr:new");
2349 f_ctrs_cn_verify();
2350
2351 f_shutdown_helper();
2352}
2353
2354/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
2355 * osmo-hnbgw.cfg). */
2356testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
2357 f_TC_cnpool_L3Complete_valid_nri_1(ps_domain := false);
2358}
2359testcase TC_sgsnpool_L3Complete_valid_nri_1() runs on test_CT {
2360 f_TC_cnpool_L3Complete_valid_nri_1(ps_domain := true);
2361}
2362function f_TC_cnpool_L3Complete_valid_nri_1(boolean ps_domain) runs on test_CT {
2363
2364 f_init(nr_msc := 2, nr_sgsn := 2);
2365 f_sleep(1.0);
2366
2367 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
2368 * this is not using round-robin. */
2369 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2370
2371 f_ctrs_cn_init(ps_domain := ps_domain);
2372
2373 var ro_octetstring compl3;
2374
2375 /* 3 NRIs of the second MSC's range (256-511) */
2376 var ro_MobileIdentityLV mis := {
2377 valueof(ts_MI_TMSI_NRI_LV(256)),
2378 valueof(ts_MI_TMSI_NRI_LV(260)),
2379 valueof(ts_MI_TMSI_NRI_LV(511))
2380 };
2381 if (ps_domain) {
2382 compl3 := {
2383 f_gen_one_compl_l3(RAUREQ, mis[0], 256),
2384 f_gen_one_compl_l3(RAUREQ, mis[1], 260),
2385 f_gen_one_compl_l3(RAUREQ, mis[2], 511)
2386 };
2387 } else {
2388 compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2389 }
2390
2391 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {1, 1, 1}, "cnpool:subscr:known");
2392
2393 f_shutdown_helper();
2394}
2395
2396/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-hnbgw.cfg),
2397 * while a round-robin remains unaffected by that. */
2398testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
2399 f_TC_cnpool_L3Complete_valid_nri_2(ps_domain := false);
2400}
2401testcase TC_sgsnpool_L3Complete_valid_nri_2() runs on test_CT {
2402 f_TC_cnpool_L3Complete_valid_nri_2(ps_domain := true);
2403}
2404function f_TC_cnpool_L3Complete_valid_nri_2(boolean ps_domain) runs on test_CT {
2405
2406 f_init(nr_msc := 3, nr_sgsn := 3);
2407 f_sleep(1.0);
2408
2409 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
2410 * this is not using round-robin. */
2411 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 1);
2412
2413 f_ctrs_cn_init(ps_domain := ps_domain);
2414
2415 var ro_octetstring compl3;
2416
2417 /* 2 NRIs of the third MSC's range (512-767) */
2418 var ro_MobileIdentityLV mis := {
2419 valueof(ts_MI_TMSI_NRI_LV(512)),
2420 valueof(ts_MI_TMSI_NRI_LV(678))
2421 };
2422 if (ps_domain) {
2423 compl3 := {
2424 f_gen_one_compl_l3(ATTACHREQ, mis[0], 512),
2425 f_gen_one_compl_l3(ATTACHREQ, mis[1], 678)
2426 };
2427 } else {
2428 compl3 := f_gen_compl3_by_domain(ps_domain, 2, mis);
2429 }
2430
2431 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {2, 2}, "cnpool:subscr:known");
2432
2433 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
2434 f_TC_cnpool_compl_l3_list(ps_domain, f_gen_compl3_by_domain(ps_domain, 1), {1}, "cnpool:subscr:new");
2435
2436 f_shutdown_helper();
2437}
2438
2439/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
2440testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
2441 f_TC_cnpool_nri_from_other_PLMN(ps_domain := false);
2442}
2443testcase TC_sgsnpool_nri_from_other_PLMN() runs on test_CT {
2444 f_TC_cnpool_nri_from_other_PLMN(ps_domain := true);
2445}
2446function f_TC_cnpool_nri_from_other_PLMN(boolean ps_domain) runs on test_CT {
2447
2448 f_init(nr_msc := 3, nr_sgsn := 3);
2449 f_sleep(1.0);
2450
2451 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
2452 * instead, and hits msc 0. */
2453 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2454
2455 f_ctrs_cn_init(ps_domain := ps_domain);
2456
2457 var ro_octetstring compl3;
2458
2459 var ro_MobileIdentityLV mis := {
2460 valueof(ts_MI_TMSI_NRI_LV(260)),
2461 valueof(ts_MI_TMSI_NRI_LV(555))
2462 };
2463 if (ps_domain) {
2464 compl3 := {
2465 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-hnbgw.cfg */
2466 enc_PDU_L3_MS_SGSN(valueof(ts_GMM_ATTACH_REQ(mis[0], f_RAI('999'H, '99'H, '2a2a'O,
2467 '17'O),
2468 nri := ts_GMM_NRI(260)
2469 ))),
2470 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
2471 f_gen_one_compl_l3(ATTACHREQ, mis[1], 555)
2472 }
2473 } else {
2474 compl3 := {
2475 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-hnbgw.cfg */
2476 enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, mis[0], '99F999'O))),
2477 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
2478 enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, mis[1], '00F110'O)))
2479 };
2480 }
2481
2482 /* Foreign NRI: roundrobin */
2483 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2484
2485 /* Local NRI: matching msc */
2486 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 2, inc_countername := "cnpool:subscr:known");
2487
2488 f_shutdown_helper();
2489}
2490
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02002491/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
2492 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
2493friend function f_tc_mscpool_paging_imsi(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2494 f_init_handler(pars);
2495
2496 var hexstring imsi := '001010000000123'H;
2497 var RANAP_IEs.CN_DomainIndicator domain_ind;
2498 if (pars.ps_domain) {
2499 domain_ind := ps_domain;
2500 } else {
2501 domain_ind := cs_domain;
2502 }
2503 var template (value) RANAP_PDU paging := ts_RANAP_Paging(domain_ind, imsi_hex2oct(imsi));
2504 BSSAP.send(ts_RANAP_UNITDATA_req(pars.sccp_addr_hnbgw, pars.sccp_addr_msc, paging));
2505 /* TODO: Expect RUA ConnectionlessTransfer Paging (on all HNB).
2506 * We could verify the Paging sent from osmo-hnbgw to RUA with some effort,
2507 * but, this test does not care whether the Paging was forwarded to RUA or not, only that osmo-hnbgw *received*
2508 * the Paging. In the CN pool decisions, osmo-hnbgw should match up Paging Response to an earlier Paging.
2509 */
2510
2511 f_sleep(1.0);
2512
2513 /* Despite the round robin pointing at the second MSC ('roundrobin next msc 1'), the earlier Paging for the same IMSI
2514 * causes this Paging Response to go to the first MSC ('msc 0'). */
2515 f_perform_compl_l3(f_gen_one_compl_l3(PAGRESP, ts_MI_IMSI_LV(imsi)));
2516 f_sleep(1.0);
2517}
2518
2519testcase TC_mscpool_paging_imsi() runs on test_CT {
2520 f_init(nr_msc := 3);
2521 f_sleep(1.0);
2522
2523 var boolean ps_domain := false;
2524
2525 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
2526 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
2527 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2528
2529 f_ctrs_cn_init(ps_domain := ps_domain);
2530
2531 var ConnHdlr vc_conn1;
2532 var template (value) TestHdlrParams pars1 := t_pars(0, ps_domain := ps_domain, cn_nr := 0);
2533 pars1.sccp_addr_hnbgw := g_cn[valueof(pars1.cn_idx)].sccp_addr_peer;
2534 pars1.sccp_addr_msc := g_cn[valueof(pars1.cn_idx)].sccp_addr_own;
2535 vc_conn1 := f_start_handler_with_pars(refers(f_tc_mscpool_paging_imsi), pars1);
2536 vc_conn1.done;
2537 f_ctrs_cn_expect(0, "cnpool:subscr:paged");
2538 f_shutdown_helper();
2539}
2540
2541/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
2542 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
2543friend function f_tc_mscpool_paging_tmsi(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2544 f_init_handler(pars);
2545
2546 var hexstring imsi := '001010000000124'H;
2547 var integer nri_v := 300; /* <-- second MSC's NRI */
2548 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
2549
2550 var RANAP_IEs.CN_DomainIndicator domain_ind;
2551 if (pars.ps_domain) {
2552 domain_ind := ps_domain;
2553 } else {
2554 domain_ind := cs_domain;
2555 }
2556 var template (value) RANAP_PDU paging := ts_RANAP_Paging_temp_id(domain_ind, imsi_hex2oct(imsi),
2557 ts_RANAP_TemporaryUE_ID_TMSI(tmsi));
2558 BSSAP.send(ts_RANAP_UNITDATA_req(pars.sccp_addr_hnbgw, pars.sccp_addr_msc, paging));
2559 /* TODO: Expect RUA ConnectionlessTransfer Paging (on all HNB).
2560 * We could verify the Paging sent from osmo-hnbgw to RUA with some effort,
2561 * but, this test does not care whether the Paging was forwarded to RUA or not, only that osmo-hnbgw *received*
2562 * the Paging. In the CN pool decisions, osmo-hnbgw should match up Paging Response to an earlier Paging.
2563 */
2564
2565 f_sleep(1.0);
2566
2567 /* Despite the round robin pointing at the third MSC ('roundrobin next msc 2'), the earlier Paging for the same
2568 * TMSI causes this Paging Response to go to the first MSC ('msc 0'). */
2569 f_perform_compl_l3(f_gen_one_compl_l3(PAGRESP, ts_MI_TMSI_NRI_LV(nri_v)));
2570 f_sleep(1.0);
2571}
2572testcase TC_mscpool_paging_tmsi() runs on test_CT {
2573 f_init(nr_msc := 3);
2574 f_sleep(1.0);
2575
2576 var boolean ps_domain := false;
2577
2578 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
2579 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
2580 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2581
2582 f_ctrs_cn_init(ps_domain := ps_domain);
2583
2584 var ConnHdlr vc_conn1;
2585 var template (value) TestHdlrParams pars1 := t_pars(0, ps_domain := ps_domain, cn_nr := 0);
2586 pars1.sccp_addr_hnbgw := g_cn[valueof(pars1.cn_idx)].sccp_addr_peer;
2587 pars1.sccp_addr_msc := g_cn[valueof(pars1.cn_idx)].sccp_addr_own;
2588 vc_conn1 := f_start_handler_with_pars(refers(f_tc_mscpool_paging_tmsi), pars1);
2589 vc_conn1.done;
2590 f_ctrs_cn_expect(0, "cnpool:subscr:paged");
2591 f_shutdown_helper();
2592}
2593
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002594/* For round-robin, skip a CN link that has 'no allow-attach' set. */
2595testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
2596
2597 f_init(nr_msc := 3);
2598 f_sleep(1.0);
2599
2600 var boolean ps_domain := false;
2601
2602 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
2603 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, {true, false, true});
2604
2605 /* Control which MSC gets chosen next by the round-robin, otherwise
2606 * would be randomly affected by which other tests ran before this. */
2607 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2608
2609 f_ctrs_cn_init(ps_domain := ps_domain);
2610
2611 f_TC_cnpool_compl_l3_list(ps_domain, f_gen_compl3_by_domain(ps_domain, 3),
2612 /* msc 1 is skipped */
2613 {0, 2, 0},
2614 "cnpool:subscr:new");
2615
2616 f_shutdown_helper();
2617}
2618
2619/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
2620 * TMSI NRI. */
2621testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
2622
2623 f_init(nr_msc := 3);
2624 f_sleep(1.0);
2625
2626 var boolean ps_domain := false;
2627
2628 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
2629 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, {true, false, true});
2630
2631 /* Control which MSC gets chosen next by the round-robin, otherwise
2632 * would be randomly affected by which other tests ran before this. */
2633 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2634
2635 f_ctrs_cn_init(ps_domain := ps_domain);
2636
2637 var ro_MobileIdentityLV mis := {
2638 valueof(ts_MI_TMSI_NRI_LV(260)),
2639 valueof(ts_MI_IMSI_LV('001010000000002'H)),
2640 valueof(ts_MI_IMSI_LV('001010000000003'H))
2641 };
2642
2643 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2644
2645 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
2646 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 1, inc_countername := "cnpool:subscr:known");
2647
2648 /* Normal round robin skips msc 1, because it has 'no allow-attach' */
2649 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2650 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 2, inc_countername := "cnpool:subscr:new");
2651
2652 f_shutdown_helper();
2653}
2654
2655/* When a peer point-code gets an SCCP N-PCSTATE saying it is unreachable, immediately mark the CN link as unusable. */
2656testcase TC_mscpool_sccp_n_pcstate_detaches_cnlink() runs on test_CT {
2657 f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(ps_domain := false);
2658}
2659testcase TC_sgsnpool_sccp_n_pcstate_detaches_cnlink() runs on test_CT {
2660 f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(ps_domain := true);
2661}
2662function f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(boolean ps_domain) runs on test_CT
2663{
2664
2665 f_init(nr_msc := 2, nr_sgsn := 2);
2666 f_sleep(1.0);
2667
2668 /* Control which MSC gets chosen next by the round-robin, otherwise
2669 * would be randomly affected by which other tests ran before this. */
2670 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2671
2672 f_ctrs_cn_init(ps_domain := ps_domain);
2673
2674 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2675
2676 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2677 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2678
2679 f_logp(HNBGWVTY, "disconnecting msc0");
2680 f_cn_idx_disconnect(f_cn_idx(ps_domain, 0));
2681
2682 /* Now round-robin would wrap to the first MSC, but since the first MSC is disconnected, it wraps around to the
2683 * second. */
2684 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2685
2686 f_shutdown_helper();
2687}
2688
2689/* When a CN link point-code gets an SCCP N-PCSTATE saying it is now reachable, immediately trigger RESET and bring up the
2690 * MSC. */
2691testcase TC_mscpool_sccp_n_pcstate_attaches_cnlink() runs on test_CT {
2692 f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(ps_domain := false);
2693}
2694testcase TC_sgsnpool_sccp_n_pcstate_attaches_cnlink() runs on test_CT {
2695 f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(ps_domain := true);
2696}
2697function f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(boolean ps_domain) runs on test_CT
2698{
2699 f_init(nr_msc := 1, nr_sgsn := 1);
2700 f_sleep(1.0);
2701
2702 /* Control which MSC gets chosen next by the round-robin, otherwise
2703 * would be randomly affected by which other tests ran before this. */
2704 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2705
2706 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2707
2708 f_ctrs_cn_init(ps_domain := ps_domain);
2709
2710 /* There is only one MSC, round robin stays on msc0 */
2711 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2712 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[1], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2713
2714 f_logp(HNBGWVTY, "connecting cnlink 1");
2715 f_cn_nr_init(ps_domain, 1);
2716 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, { true, true });
2717 f_sleep(1.0);
2718
2719 /* This time round-robin wraps to the second MSC, because it is now online. */
2720 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[2], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2721
2722 f_shutdown_helper();
2723}
2724
Neels Hofmeyrd019cc02023-06-02 16:31:23 +02002725private function f_vty_add_sccp_addr(TELNETasp_PT pt, charstring addr_name, charstring pc, integer cs7_nr := 0)
2726{
2727 f_vty_enter_config(pt);
2728 f_vty_transceive(pt, "cs7 instance 0");
2729 f_vty_transceive(pt, "sccp-address " & addr_name);
2730 f_vty_transceive(pt, "point-code " & pc);
2731 f_vty_transceive(pt, "end");
2732}
2733
2734private function f_vty_set_cnlink_addr(TELNETasp_PT pt, charstring cnlink_and_nr, charstring addr_name)
2735{
2736 f_vty_enter_config(pt);
2737 f_vty_transceive(pt, cnlink_and_nr);
2738 f_vty_transceive(pt, "remote-addr " & addr_name);
2739 f_vty_transceive(pt, "end");
2740}
2741
2742private function f_vty_apply_sccp(TELNETasp_PT pt)
2743{
2744 f_vty_enter_config(pt);
2745 f_vty_transceive(pt, "apply sccp");
2746 f_vty_transceive(pt, "end");
2747}
2748
2749template (present) RUA_Disc_Req tr_RUA_Disc_Req := {
2750 ranap := ?,
2751 cause := ?
2752};
2753
2754/* With a cnlink up, change the SCCP address, and verify that it restarts upon vty 'apply sccp' */
2755private function f_tc_apply_sccp(charstring id, TestHdlrParams pars) runs on ConnHdlr
2756{
2757 f_init_handler(pars);
2758 f_perform_compl_l3(f_gen_compl3_by_domain(pars.ps_domain, 1)[0]);
2759
2760 f_sleep(1.0);
2761 f_logp(HNBGWVTY, "Changing SCCP address, don't apply yet");
2762
2763 f_vty_add_sccp_addr(HNBGWVTY, "msc-foo", "0.42.4");
2764 f_vty_set_cnlink_addr(HNBGWVTY, "msc 0", "msc-foo");
2765
2766 /* No effect yet, link still open both ways */
2767 f_sleep(1.0);
2768 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
2769 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
2770
2771 f_logp(HNBGWVTY, "Apply SCCP address changes");
2772 f_vty_apply_sccp(HNBGWVTY);
2773
2774 /* We modified the SCCP configuration, expect disconnect of UE that was active on the aborted link. */
2775 RUA.receive(RUA_Disc_Ind:?);
2776 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
2777
2778 /* Would be nice to test reconnection on the other point-code, too. That would require another cnlink in
2779 * osmo-stp.cfg and module parameters... */
2780
2781 f_sleep(1.0);
2782}
2783testcase TC_apply_sccp() runs on test_CT
2784{
2785 f_init();
2786 f_sleep(1.0);
2787
2788 var ConnHdlr vc_conn;
2789 var template (value) TestHdlrParams pars := t_pars(0);
2790 vc_conn := f_start_handler_with_pars(refers(f_tc_apply_sccp), pars);
2791 vc_conn.done;
2792
2793 f_shutdown_helper();
2794}
2795
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002796/* In the field, we encountered a "normal" RAB Assignment that concludes successfully, followed by another RAB
2797 * Assignment that has different SDU subflow parameters, and does not contain RTP information. At the time of writing,
2798 * it seems that the second RAB Assignment causes a crash. Play through this scenario. */
2799friend function f_tc_second_rab_assignment(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2800 var MgcpCommand mgcp_cmd;
2801 var RANAP_PDU tx;
2802 timer T := 5.0;
2803
2804 f_init_handler(pars);
2805 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
2806
2807 tx := f_build_initial_ue(g_pars);
2808 f_iuh2iu_connect(tx);
2809
2810 f_create_rab(pars.mgcp_pars);
2811
2812 /* Now send a second RAB Assignment with different subflows and omitting transportLayerInformation. (Assuming
2813 * the first RAB Assignment's transportLayerInformation remains in use unchanged.) */
2814 var template RAB_SetupOrModifyList rab_sml;
2815 rab_sml := ts_RAB_SML2(t_RAB_id(23),
2816 ts_RabParams,
2817 user_plane_info := omit,
2818 transport_layer_info := omit);
2819 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
2820 BSSAP.send(tx);
2821 T.start;
2822
2823 /* Expect this secondary RAB Assignment to go through unchanged. */
2824 f_rua_expect(tx);
2825
2826 /* I'm guessing that the RAB Assignment Response also omits transportLayerInformation, so far not known because
2827 * osmo-hnbgw crashed before we could receive the response. */
2828
2829 /* Send back RAB Assignment Response via Iuh */
2830 var template RAB_SetupOrModifiedList rab_smdl;
2831 rab_smdl := ts_RAB_SMdL_no_tla(t_RAB_id(23));
2832 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
2833 RUA.send(tx);
2834 f_bssap_expect(tx);
2835
2836 /* Send Iu Release */
Harald Welte0d4a8432024-04-04 01:12:11 +02002837 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002838 f_iu2iuh(tx);
2839
2840 T.start;
2841 alt {
2842 [] as_mgcp_dlcx(pars) {}
2843 [] T.timeout {
2844 setverdict(fail, "Timeout waiting for DLCX");
2845 }
2846 }
2847
2848 tx := valueof(ts_RANAP_IuReleaseComplete());
2849 f_iuh2iu(tx);
2850}
2851
2852testcase TC_second_rab_assignment() runs on test_CT {
2853 var ConnHdlr vc_conn;
2854 g_num_hnbs := 1;
2855 f_init();
2856
2857 vc_conn := f_start_handler_with_pars(refers(f_tc_second_rab_assignment), t_pars(3));
2858 vc_conn.done;
2859
2860 f_shutdown_helper();
2861}
2862
Daniel Willmann19b8d902022-01-05 09:12:34 +01002863control {
2864 execute(TC_hnb_register());
Daniel Willmannc79679a2022-08-23 17:48:39 +02002865 execute(TC_hnb_register_duplicate());
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +02002866 execute(TC_hnb_register_duplicate_reuse_sctp_assoc());
Harald Welteaf3e2162024-03-27 21:54:20 +01002867 execute(TC_ue_register());
Harald Weltef60044d2024-04-04 00:54:34 +02002868 execute(TC_ue_register_tmsi_lai());
Harald Welteaf3e2162024-03-27 21:54:20 +01002869 execute(TC_ue_register_before_hnb_register());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002870 execute(TC_ranap_cs_initial_ue());
2871 execute(TC_ranap_ps_initial_ue());
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02002872 execute(TC_ranap_cs_initial_ue_empty_cr());
2873 execute(TC_ranap_ps_initial_ue_empty_cr());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002874 execute(TC_ranap_cs_bidir());
2875 execute(TC_ranap_ps_bidir());
2876 execute(TC_rab_assignment());
2877 execute(TC_rab_release());
Harald Weltef95ab2d2024-04-04 01:32:20 +02002878 execute(TC_rab_release_abnormal());
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01002879 execute(TC_rab_assign_fail());
Daniel Willmann37c877f2022-02-22 16:47:06 +01002880 execute(TC_rab_assign_mgcp_to());
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01002881 execute(TC_rab_assign_mgw_iuup_addr_chg());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002882 execute(TC_ranap_cs_mo_disconnect());
2883 execute(TC_ranap_ps_mo_disconnect());
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02002884
2885 if (mp_enable_pfcp_tests) {
2886 execute(TC_ps_rab_assignment_with_pfcp());
2887 } else {
2888 execute(TC_ps_rab_assignment_without_pfcp());
2889 }
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02002890
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002891 execute( TC_mscpool_L3Compl_on_1_cnlink() );
2892 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
2893 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
2894 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
2895 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
2896 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
2897 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
2898 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
2899 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02002900 execute( TC_mscpool_paging_imsi() );
2901 execute( TC_mscpool_paging_tmsi() );
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002902 execute( TC_mscpool_no_allow_attach_round_robin() );
2903 execute( TC_mscpool_no_allow_attach_valid_nri() );
2904 execute( TC_mscpool_sccp_n_pcstate_detaches_cnlink() );
2905 execute( TC_mscpool_sccp_n_pcstate_attaches_cnlink() );
2906
2907 execute( TC_sgsnpool_L3Compl_on_1_cnlink() );
2908 execute( TC_sgsnpool_L3Complete_no_nri_round_robin() );
2909 execute( TC_sgsnpool_L3Complete_valid_nri_1() );
2910 execute( TC_sgsnpool_L3Complete_valid_nri_2() );
2911 execute( TC_sgsnpool_nri_from_other_PLMN() );
2912 execute( TC_sgsnpool_sccp_n_pcstate_detaches_cnlink() );
2913 execute( TC_sgsnpool_sccp_n_pcstate_attaches_cnlink() );
2914
Oliver Smithaa919b42023-11-14 11:30:55 +01002915 /* Run only on nightly since it makes osmo-hnbgw <= 1.5.0 crash: OS#6253 */
2916 if (f_osmo_repo_is("nightly")) {
2917 execute(TC_second_rab_assignment());
2918 }
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002919
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02002920 /* Run at the end since it makes osmo-hnbgw <= 1.3.0 crash: OS#5676 */
2921 execute(TC_hnb_reregister_reuse_sctp_assoc());
Neels Hofmeyrd019cc02023-06-02 16:31:23 +02002922
2923 /* Run at the end since it messes with the SCCP config */
2924 execute( TC_apply_sccp() );
Daniel Willmann19b8d902022-01-05 09:12:34 +01002925}
2926
2927}