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