blob: 15fc85f6555b726cfd4b87586f2b8212a2b50d23 [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;
36import from HNBAP_PDU_Descriptions all;
37
38import from RUA_IEs all;
39import from RUA_Templates all;
40import from RUA_Emulation all;
41
42import from Iuh_Emulation all;
43
44import from RANAP_Types all;
45import from RANAP_PDU_Descriptions all;
46import from RANAP_PDU_Contents all;
47import from RANAP_IEs all;
48import from RANAP_Templates all;
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +020049import from RANAP_CodecPort all;
Daniel Willmann19b8d902022-01-05 09:12:34 +010050
51import from RAN_Adapter all;
Daniel Willmann19b8d902022-01-05 09:12:34 +010052import from RAN_Emulation all;
53
54import from MGCP_Emulation all;
55import from MGCP_Types all;
56import from MGCP_Templates all;
57import from MGCP_CodecPort all;
58import from SDP_Types all;
59
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +020060import from PFCP_Types all;
61import from PFCP_Emulation all;
62import from PFCP_Templates all;
63import from PFCP_CodecPort all;
64
Neels Hofmeyr75d905b2023-04-27 00:30:25 +020065import from TCCConversion_Functions all;
Neels Hofmeyr7a48df12023-04-20 20:43:43 +020066import from MobileL3_Types all;
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +020067import from MobileL3_CommonIE_Types all;
68import from MobileL3_GMM_SM_Types all;
Neels Hofmeyr7a48df12023-04-20 20:43:43 +020069import from L3_Templates all;
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +020070import from L3_Common all;
Neels Hofmeyr7a48df12023-04-20 20:43:43 +020071
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +020072import from SCCPasp_Types all;
73
Neels Hofmeyr7a48df12023-04-20 20:43:43 +020074const integer NUM_MSC := 4;
75const integer NUM_SGSN := 4;
76
77const integer FIRST_MSC_IDX := 0;
78const integer FIRST_SGSN_IDX := NUM_MSC;
Neels Hofmeyr75d905b2023-04-27 00:30:25 +020079
Daniel Willmann19b8d902022-01-05 09:12:34 +010080modulepar {
81 /* IP address at which the HNodeB can be reached */
82 charstring mp_hnodeb_ip := "127.0.0.1";
83 integer mp_hnodeb_port := -1;
84
85 /* IP address at which the test binds */
86 charstring mp_hnbgw_ip := "127.0.0.1";
87 integer mp_hnbgw_iuh_port := 29169;
Neels Hofmeyrffcb8892023-06-27 01:09:57 +020088 integer mp_hnbgw_ctrl_port := 4262;
Daniel Willmann19b8d902022-01-05 09:12:34 +010089
90 charstring mp_mgw_ip := "127.0.0.1";
91 integer mp_mgw_port := 2427;
92
Neels Hofmeyr7a48df12023-04-20 20:43:43 +020093 RAN_Configurations mp_cn_cfg := {
94 /* MSCs (NUM_MSC entries) */
95 {
96 transport := RANAP_TRANSPORT_IuCS,
97 sccp_service_type := "mtp3_itu",
98 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
99 own_pc := 188, /* 0.23.4 first MSC emulation */
100 own_ssn := 142,
101 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
102 peer_ssn := 142,
103 sio := '83'O,
104 rctx := 1
105 },
106 {
107 transport := RANAP_TRANSPORT_IuCS,
108 sccp_service_type := "mtp3_itu",
109 sctp_addr := { 23907, "127.0.0.1", 2905, "127.0.0.1" },
110 own_pc := 2, /* 0.0.2 second MSC emulation */
111 own_ssn := 142,
112 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
113 peer_ssn := 142,
114 sio := '83'O,
115 rctx := 3
116 },
117 {
118 transport := RANAP_TRANSPORT_IuCS,
119 sccp_service_type := "mtp3_itu",
120 sctp_addr := { 23909, "127.0.0.1", 2905, "127.0.0.1" },
121 own_pc := 3, /* 0.0.3 third MSC emulation */
122 own_ssn := 142,
123 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
124 peer_ssn := 142,
125 sio := '83'O,
126 rctx := 5
127 },
128 {
129 transport := RANAP_TRANSPORT_IuCS,
130 sccp_service_type := "mtp3_itu",
131 sctp_addr := { 23911, "127.0.0.1", 2905, "127.0.0.1" },
132 own_pc := 4, /* 0.0.4 fourth MSC emulation */
133 own_ssn := 142,
134 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
135 peer_ssn := 142,
136 sio := '83'O,
137 rctx := 7
138 },
139
140 /* SGSNs (NUM_SGSN entries) */
141 {
142 transport := RANAP_TRANSPORT_IuCS,
143 sccp_service_type := "mtp3_itu",
144 sctp_addr := { /* local */ 23906, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
145 own_pc := 185, /* 0.23.1 first SGSN emulation */
146 own_ssn := 142,
147 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
148 peer_ssn := 142,
149 sio := '83'O,
150 rctx := 2
151 },
152 {
153 transport := RANAP_TRANSPORT_IuCS,
154 sccp_service_type := "mtp3_itu",
155 sctp_addr := { /* local */ 23908, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
156 own_pc := 10, /* 0.1.2 second SGSN emulation */
157 own_ssn := 142,
158 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
159 peer_ssn := 142,
160 sio := '83'O,
161 rctx := 4
162 },
163 {
164 transport := RANAP_TRANSPORT_IuCS,
165 sccp_service_type := "mtp3_itu",
166 sctp_addr := { /* local */ 23910, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
167 own_pc := 11, /* 0.1.3 third SGSN emulation */
168 own_ssn := 142,
169 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
170 peer_ssn := 142,
171 sio := '83'O,
172 rctx := 6
173 },
174 {
175 transport := RANAP_TRANSPORT_IuCS,
176 sccp_service_type := "mtp3_itu",
177 sctp_addr := { /* local */ 23912, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
178 own_pc := 12, /* 0.1.4 fourth SGSN emulation */
179 own_ssn := 142,
180 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
181 peer_ssn := 142,
182 sio := '83'O,
183 rctx := 8
184 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100185 };
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200186
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +0200187 boolean mp_enable_pfcp_tests := false;
188
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200189 /* IP address at which we listen for PFCP to emulate a UPF in ttcn3 */
190 charstring mp_pfcp_ip_local := "127.0.0.1";
191
192 /* IP address from which the SUT (osmo-hnbgw) sends PFCP requests, and to which the ttcn3 UPF emulation sends
193 * PFCP responses. */
194 charstring mp_pfcp_ip_remote := "127.0.0.2";
Pau Espin Pedrol6c87ad92023-07-18 11:24:25 +0200195
196 boolean mp_validate_talloc_asn1 := true;
Pau Espin Pedrolee4ce862023-11-02 12:23:25 +0100197
198 /* The X31 timer configured at osmo-hnbgw (seconds). This provided an idea on
199 * minimum time the test must wait to consider this timer triggered */
200 integer mp_hnbgw_timer_x31 := 5;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100201}
202
203function MSC_UnitdataCallback(RANAP_PDU ranap) runs on RAN_Emulation_CT return template RANAP_PDU {
204 // TODO: Actually implement unitdata handling
Neels Hofmeyrcf6dc492023-06-27 00:51:08 +0200205 return omit;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100206}
207
208const RanOps MSC_RanOps := {
209 ranap_create_cb := refers(RAN_Emulation.RanapExpectedCreateCallback),
210 ranap_unitdata_cb := refers(MSC_UnitdataCallback),
211 ps_domain := false,
212 decode_dtap := false,
213 role_ms := false,
214 protocol := RAN_PROTOCOL_RANAP,
215 transport := RANAP_TRANSPORT_IuCS,
216 use_osmux := false,
Eric Wild6e511ce2022-04-02 21:35:56 +0200217 bssap_reset_retries := 1,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100218 sccp_addr_local := omit,
219 sccp_addr_peer := omit
220}
221
Pau Espin Pedrol264679f2023-11-29 15:52:00 +0100222type record MgwResponse {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100223 integer resp,
224 HostName mgw_rtp_ip,
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +0100225 /* if set, used after first received MDCX: */
226 HostName mgw_rtp_ip_mdcx optional,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100227 PortNumber mgw_rtp_port,
228 MgcpConnectionId mgcp_connection_id
229}
230type record MgcpParameters {
231 integer got_crcx_count,
232 integer got_dlcx_count,
233 MgcpCallId mgcp_call_id optional,
234 MgcpEndpoint mgcp_ep,
Pau Espin Pedrol264679f2023-11-29 15:52:00 +0100235 MgwResponse mgw_conn_ran,
236 MgwResponse mgw_conn_cn,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100237 uint7_t rtp_payload_type,
238 charstring rtp_sdp_format,
239 HostName hnb_rtp_ip,
240 PortNumber hnb_rtp_port,
241 HostName cn_rtp_ip,
242 PortNumber cn_rtp_port,
243 boolean use_osmux,
244 integer got_osmux_count
245}
246
247template (value) MgcpParameters t_MgcpParams := {
248 got_crcx_count := 0,
249 got_dlcx_count := 0,
250 mgcp_call_id := omit,
251 mgcp_ep := "rtpbridge/1@mgw",
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +0100252 mgw_conn_ran := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100253 resp := 1,
254 mgw_rtp_ip := "127.1.2.1",
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +0100255 mgw_rtp_ip_mdcx := omit,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100256 mgw_rtp_port := 10000,
257 mgcp_connection_id := '11111'H
258 },
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +0100259 mgw_conn_cn := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100260 resp := 1,
261 mgw_rtp_ip := "127.1.2.2",
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +0100262 mgw_rtp_ip_mdcx := omit,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100263 mgw_rtp_port := 20000,
264 mgcp_connection_id := '22222'H
265 },
Philipp Maier6c5ba0752023-07-04 16:53:40 +0200266 rtp_payload_type := 112,
267 rtp_sdp_format := "VND.3GPP.IUFP",
Daniel Willmann19b8d902022-01-05 09:12:34 +0100268 hnb_rtp_ip := "127.1.1.1",
269 hnb_rtp_port := 10001,
270 cn_rtp_ip := "127.1.3.1",
271 cn_rtp_port := 20001,
272 use_osmux := false,
273 got_osmux_count := 0
274}
275
276type record TestHdlrParams {
277 integer hnb_idx,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200278 /* cn_idx indicates which CN link from g_cn[] to connect to the test component.
279 * See also f_cn_idx(). */
280 integer cn_idx,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100281 hexstring imsi,
282 boolean ps_domain,
283 MgcpParameters mgcp_pars optional,
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200284 HnbConfig hnb optional,
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200285 boolean expect_separate_sccp_cr,
286 integer tx_sccp_cr_data_len,
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +0200287 charstring pfcp_local_addr,
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +0200288 octetstring nas_pdu optional,
289 /* local and remote SCCP addresses, used in TC_mscpool_paging_* */
290 SCCP_PAR_Address sccp_addr_msc optional,
291 SCCP_PAR_Address sccp_addr_hnbgw optional
Daniel Willmann19b8d902022-01-05 09:12:34 +0100292}
293
294/* We extend:
295 * RUA_ConnHdlr (for the Iuh side, emulating the HNB)
296 * RAN_ConnHdlr (for the Iu side, emulating the MSC)
297 * MGCP_ConnHdlr (for the MGCP side, emulating the MGW)
298 */
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200299type component ConnHdlr extends RAN_ConnHdlr, MGCP_ConnHdlr, RUA_ConnHdlr, PFCP_ConnHdlr {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100300 var integer g_sccp_conn_id;
301 var TestHdlrParams g_pars;
302 timer g_Tguard;
Neels Hofmeyr72a8d622023-01-26 13:47:01 +0100303
304 port TELNETasp_PT HNBGWVTY;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100305}
306
307
308const MGCPOps MSC_MGCPOps := {
309 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
310 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
311}
312
313function f_create_ranap_exp(octetstring l3_enc) runs on ConnHdlr {
314 BSSAP_PROC.call(RAN_register:{l3_enc, self}) {
315 [] BSSAP_PROC.getreply(RAN_register:{?, ?}) {};
316 }
317}
318
319
Daniel Willmannc79679a2022-08-23 17:48:39 +0200320const integer NUM_HNB := 2;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100321
Daniel Willmann19b8d902022-01-05 09:12:34 +0100322type record HnbConfig {
323 LocationAreaIdentification lai,
324 integer sac
325}
326
327type component test_CT extends CTRL_Adapter_CT {
328 var boolean g_initialized := false;
329
330 /********************* Iu side */
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200331 var RAN_Adapter g_cn[NUM_MSC + NUM_SGSN];
Daniel Willmann19b8d902022-01-05 09:12:34 +0100332
333 /********************* Iuh side */
334 var HnbConfig g_hnb_cfg[NUM_HNB];
335 var Iuh_Emulation_CT vc_Iuh[NUM_HNB];
336 var RUA_Emulation_CT vc_RUA[NUM_HNB];
337 port HNBAP_PT HNBAP[NUM_HNB];
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200338 /* Number of HNBs to be used/started by the test */
339 var integer g_num_hnbs := NUM_HNB;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100340
341 var MGCP_Emulation_CT vc_MGCP;
342 port TELNETasp_PT HNBGWVTY;
343 /* global test case guard timer (actual timeout value is set in f_init()) */
344 timer T_guard := 30.0;
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +0200345
346 /* The cnlink type 'msc' or 'sgsn', to be used in CTRL commands to obtain counters */
347 var charstring g_ctr_cn_node_name;
348 /* Counter state */
349 var CounterNameValsList g_ctr_cn;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100350}
351
352/* global altstep for global guard timer; */
353altstep as_Tguard() runs on test_CT {
354 [] T_guard.timeout {
355 setverdict(fail, "Timeout of T_guard");
356 mtc.stop;
357 }
358}
359
Daniel Willmann19b8d902022-01-05 09:12:34 +0100360function f_init_vty(charstring id := "foo") runs on test_CT {
361 if (HNBGWVTY.checkstate("Mapped")) {
362 /* skip initialization if already executed once */
363 return;
364 }
365 map(self:HNBGWVTY, system:HNBGWVTY);
366 f_vty_set_prompts(HNBGWVTY);
367 f_vty_transceive(HNBGWVTY, "enable");
368}
369
370function f_init_mgcp(charstring id) runs on test_CT {
371 id := id & "-MGCP";
372 var MGCPOps ops := {
373 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
374 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
375 }
376 var MGCP_conn_parameters pars := {
377 callagent_ip := mp_hnbgw_ip,
378 callagent_udp_port := -1,
379 mgw_ip := mp_mgw_ip,
380 mgw_udp_port := mp_mgw_port,
381 multi_conn_mode := false
382 }
383
384 vc_MGCP := MGCP_Emulation_CT.create(id);
385 map(vc_MGCP:MGCP, system:MGCP_CODEC_PT);
386 vc_MGCP.start(MGCP_Emulation.main(ops, pars, id));
387}
388
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200389function f_init_pfcp(charstring id) runs on ConnHdlr {
390 id := id & "-PFCP";
391
392 var PFCP_Emulation_Cfg pfcp_cfg := {
393 pfcp_bind_ip := mp_pfcp_ip_local,
394 pfcp_bind_port := PFCP_PORT,
395 pfcp_remote_ip := mp_pfcp_ip_remote,
396 pfcp_remote_port := PFCP_PORT,
397 role := UPF
398 };
399
400 vc_PFCP := PFCP_Emulation_CT.create(id) alive;
401 connect(self:PFCP, vc_PFCP:CLIENT);
402 connect(self:PFCP_PROC, vc_PFCP:CLIENT_PROC);
403 vc_PFCP.start(PFCP_Emulation.main(pfcp_cfg));
404}
405
Daniel Willmann19b8d902022-01-05 09:12:34 +0100406function f_init_hnodeb(charstring id, integer hnb_idx, RuaOps rua_ops) runs on test_CT {
407 id := id & "-Iuh" & int2str(hnb_idx);
408
409 /* Iuh lower layer (RUA/HNBAP demux) */
410 var Iuh_conn_parameters iuh_pars;
411 iuh_pars.remote_ip := mp_hnbgw_ip;
412 iuh_pars.remote_sctp_port := mp_hnbgw_iuh_port;
413 iuh_pars.local_ip := mp_hnodeb_ip;
414 iuh_pars.local_sctp_port := mp_hnodeb_port + hnb_idx;
415 vc_Iuh[hnb_idx] := Iuh_Emulation_CT.create(id);
416 connect(self:HNBAP[hnb_idx], vc_Iuh[hnb_idx]:HNBAP);
417
418 vc_RUA[hnb_idx] := RUA_Emulation_CT.create(id & "-RUA");
419 connect(vc_RUA[hnb_idx]:RUA, vc_Iuh[hnb_idx]:RUA);
420
421 /* Start Iuh side components */
422 vc_Iuh[hnb_idx].start(Iuh_Emulation.main(iuh_pars, id));
423 vc_RUA[hnb_idx].start(RUA_Emulation.main(rua_ops, id & "-RUA"));
424}
425
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200426private type record of boolean BooleanList;
427
428private function f_vty_cnlink_allow_attach(TELNETasp_PT pt, boolean ps_domain, BooleanList allow_attach_list)
429{
430 var charstring config := f_vty_transceive_ret(pt, "show running-config");
431
432 var charstring msc_sgsn;
433 if (ps_domain) {
434 msc_sgsn := "sgsn";
435 } else {
436 msc_sgsn := "msc";
437 }
438
439 f_vty_enter_config(pt);
440 for (var integer cn_nr := 0; cn_nr < sizeof(allow_attach_list); cn_nr := cn_nr+1) {
441 if (f_strstr(config, "\n" & msc_sgsn & " " & int2str(cn_nr) & "\n") < 0) {
442 /* There is no 'msc N' for this cn_nr in the running config, so don't create an empty cn by
443 * stepping into that config node. */
444 log(msc_sgsn, cn_nr, " is not configured, skipping");
445 continue;
446 }
447 f_vty_transceive(pt, msc_sgsn & " " & int2str(cn_nr));
448
449 if (allow_attach_list[cn_nr]) {
450 /* strict := false: ignore if osmo-hnbgw does not support this config option (latest build) */
451 f_vty_transceive(pt, "allow-attach", strict := false);
452 } else {
453 f_vty_transceive(pt, "no allow-attach", strict := false);
454 }
455 f_vty_transceive(pt, "exit");
456 }
457 f_vty_transceive(pt, "exit");
458}
459
460/* Start RAN adapter for CN link N.
461 * e.g. link for 'msc 0' = (ps_domain := false, cn_nr := 0)
462 * link for 'sgsn 3' = (ps_domain := true, cn_nr := 3)
463 */
464private function f_cn_nr_init(boolean ps_domain, integer cn_nr) runs on test_CT {
465 var RanOps ranops := MSC_RanOps;
466 ranops.ps_domain := ps_domain;
467 var integer cn_idx := f_cn_idx(ps_domain, cn_nr);
468 var charstring msc_sgsn := "msc";
469 if (ps_domain) {
470 msc_sgsn := "sgsn";
471 }
472 f_ran_adapter_init(g_cn[cn_idx], mp_cn_cfg[cn_idx], "HNBGW_Test." & msc_sgsn & int2str(cn_nr), ranops);
473 f_ran_adapter_start(g_cn[cn_idx]);
474}
475
476private function f_cn_idx_disconnect(integer cn_idx) runs on test_CT {
477 f_ran_adapter_cleanup(g_cn[cn_idx]);
478}
479
Daniel Willmann19b8d902022-01-05 09:12:34 +0100480/* global initialization function */
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200481function f_init(charstring id := "HNBGW", float guard_timeout := 30.0, integer nr_msc := 1, integer nr_sgsn := 1,
482 boolean start_hnb := true) runs on test_CT {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100483
Daniel Willmann19b8d902022-01-05 09:12:34 +0100484 T_guard.start(guard_timeout);
485 activate(as_Tguard());
486
487 /* RUA/RANAP emulation on top of lower-layer Iuh */
488 var RuaOps rua_ops := {
489 create_cb := refers(IuhRanapCreateCallback),
490 unitdata_cb := refers(IuhRanapUnitdataCallback)
491 };
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200492 for (var integer i := 0; i < g_num_hnbs; i := i+1) {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200493 g_hnb_cfg[i] := {
494 lai := {
Neels Hofmeyr497216f2023-06-27 00:59:26 +0200495 mcc_mnc := '00F110'H,
Daniel Willmannc79679a2022-08-23 17:48:39 +0200496 lac := 2342 + i
497 },
498 sac := 55
499 };
Daniel Willmann19b8d902022-01-05 09:12:34 +0100500 f_init_hnodeb(testcasename(), i, rua_ops);
501 }
502
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200503 f_init_vty("VirtHNBGW");
Neels Hofmeyrffcb8892023-06-27 01:09:57 +0200504 f_ipa_ctrl_start_client(mp_hnbgw_ip, mp_hnbgw_ctrl_port);
505
Daniel Willmann19b8d902022-01-05 09:12:34 +0100506 /* MSC emulation */
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200507
508 /* Make sure each MSC's internal state is "DISCONNECTED" at first */
509 for (var integer i := 0; i < NUM_MSC; i := i + 1) {
510 f_vty_transceive(HNBGWVTY, "msc " & int2str(i) & " ranap reset", strict := false);
511 }
512
513 var BooleanList allow_attach := { false, false, false, false };
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200514 for (var integer i := 0; i < nr_msc; i := i + 1) {
515 var integer cn_idx := FIRST_MSC_IDX + i;
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200516 allow_attach[i] := true;
517 f_cn_nr_init(ps_domain := false, cn_nr := i);
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200518 }
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200519 /* start the test with exactly all enabled MSCs allowed to attach */
520 f_vty_cnlink_allow_attach(HNBGWVTY, false, allow_attach);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100521
522 /* SGSN emulation */
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200523
524 /* Make sure each SGSN's internal state is "DISCONNECTED" at first */
525 for (var integer i := 0; i < NUM_SGSN; i := i + 1) {
526 f_vty_transceive(HNBGWVTY, "sgsn " & int2str(i) & " ranap reset", strict := false);
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200527 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100528
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200529 allow_attach := { false, false, false, false };
530 for (var integer i := 0; i < nr_sgsn; i := i + 1) {
531 var integer cn_idx := FIRST_SGSN_IDX + i;
532 allow_attach[i] := true;
533 f_cn_nr_init(ps_domain := true, cn_nr := i);
534 }
535 f_vty_cnlink_allow_attach(HNBGWVTY, true, allow_attach);
536
Daniel Willmann19b8d902022-01-05 09:12:34 +0100537 f_init_mgcp(id);
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200538
539 if (start_hnb) {
540 f_start_hnbs();
541 }
Neels Hofmeyr467eb7e2023-08-10 03:38:07 +0200542
543 /* Sometimes, the RUA InitialUE-Message from a test happens too quickly, before the RANAP RESET from
544 * RAN_Emulation is through, after above f_cn_nr_init(). In the pcap it seems to be a matter of 50 ms. Give some
545 * grace. */
546 f_sleep(1.0);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100547}
548
549friend function f_shutdown_helper() runs on test_CT {
Pau Espin Pedrol6c87ad92023-07-18 11:24:25 +0200550 if (mp_validate_talloc_asn1) {
551 f_verify_talloc_bytes(HNBGWVTY, {"asn1_context"}, 1);
552 }
Neels Hofmeyr75d905b2023-04-27 00:30:25 +0200553
Daniel Willmann19b8d902022-01-05 09:12:34 +0100554 all component.stop;
555 setverdict(pass);
556 mtc.stop;
557}
558
559/* helper function to start all of the simulated hNodeBs */
560function f_start_hnbs() runs on test_CT {
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200561 for (var integer i:= 0; i < g_num_hnbs; i := i+1) {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200562 f_hnbap_register(i, i);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100563 }
564}
565
566/***********************************************************************
567 * code running in test_CT, preparing start of per-UE ConnHdlr
568 ***********************************************************************/
569
570/* inbound RUA connection establishment on Iuh side */
571function IuhRanapCreateCallback(ContextId context_id, RUA_IEs.CN_DomainIndicator domain, charstring id)
572runs on RUA_Emulation_CT return RUA_ConnHdlr {
573 log("CreateCallback");
574 return null;
575}
576
577/* inbound RUA connectionless data on Iuh side */
578function IuhRanapUnitdataCallback(RANAP_PDU ranap)
579runs on RUA_Emulation_CT return template RANAP_PDU {
580 log("UnitdataCallback");
581 return omit;
582}
583
584private function f_start_handler_create(TestHdlrParams pars) runs on test_CT return ConnHdlr {
585 var ConnHdlr vc_conn;
586 var charstring id := testcasename() & int2str(pars.hnb_idx);
587
588 vc_conn := ConnHdlr.create(id);
589
590 /* Iuh RUA part */
591 connect(vc_conn:RUA, vc_RUA[pars.hnb_idx]:CLIENT);
592
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200593 /* MSC or SGSN */
594 connect(vc_conn:BSSAP, g_cn[pars.cn_idx].vc_RAN:CLIENT);
595 connect(vc_conn:BSSAP_PROC, g_cn[pars.cn_idx].vc_RAN:PROC);
596
Daniel Willmann19b8d902022-01-05 09:12:34 +0100597 /* MGCP part */
598 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
599 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
600
601 return vc_conn;
602}
603
604private function f_start_handler_run(ConnHdlr vc_conn, void_fn fn, TestHdlrParams pars) runs on test_CT {
605 var charstring id := testcasename(); // & int2str(pars.ran_idx);
606 /* We cannot use vc_conn.start(f_init_handler(fn, id, pars)); as we cannot have
607 * a stand-alone 'derefers()' call, see https://www.eclipse.org/forums/index.php/t/1091364/ */
608 pars.hnb := g_hnb_cfg[pars.hnb_idx];
Daniel Willmann19b8d902022-01-05 09:12:34 +0100609 vc_conn.start(derefers(fn)(id, pars));
610}
611
612function f_start_handler_with_pars(void_fn fn, template (value) TestHdlrParams pars)
613runs on test_CT return ConnHdlr {
614 var ConnHdlr vc_conn;
615 vc_conn := f_start_handler_create(valueof(pars));
616 f_start_handler_run(vc_conn, fn, valueof(pars));
617 return vc_conn;
618}
619
620/***********************************************************************
621 * code running inside per-UE ConnHdlr
622 ***********************************************************************/
623
624type function void_fn(charstring id, TestHdlrParams pars) runs on ConnHdlr;
625
626function f_init_handler(TestHdlrParams pars, float t_guard := 20.0) runs on ConnHdlr {
627 /* make parameters available via component variable */
628 g_pars := pars;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200629
630 f_init_pfcp(testcasename());
631
Daniel Willmann19b8d902022-01-05 09:12:34 +0100632 /* start guard timer and activate it as default */
633 g_Tguard.start(t_guard);
634 activate(as_Tguard_ConnHdlr());
635
Neels Hofmeyr72a8d622023-01-26 13:47:01 +0100636 map(self:HNBGWVTY, system:HNBGWVTY);
637 f_vty_set_prompts(HNBGWVTY);
638 f_vty_transceive(HNBGWVTY, "enable");
639
Daniel Willmann19b8d902022-01-05 09:12:34 +0100640 /* TODO: CTRL? */
Neels Hofmeyr59517222023-06-23 04:46:59 +0200641
642 f_sleep(1.0);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100643}
644
645/* global altstep for global guard timer; */
646private altstep as_Tguard_ConnHdlr() runs on ConnHdlr {
647 [] g_Tguard.timeout {
648 setverdict(fail, "Timeout of T_guard");
649 mtc.stop;
650 }
651}
652
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100653private function f_bssap_expect(template (present) RANAP_PDU exp_rx) runs on ConnHdlr return RANAP_PDU
654{
655 var RANAP_PDU rx;
656 timer T := 5.0;
657 T.start;
658 alt {
659 [] BSSAP.receive(exp_rx) -> value rx {
660 setverdict(pass);
661 }
662 [] BSSAP.receive(RANAP_PDU:?) {
663 setverdict(fail, "Got an unexpected RANAP message on BSSAP port, was waiting for ", exp_rx);
664 mtc.stop;
665 }
666 [] T.timeout {
667 setverdict(fail, "Timeout waiting for RANAP on BSSAP port: ", exp_rx);
668 mtc.stop;
669 }
670 }
671 T.stop;
672 return rx;
673}
674
Daniel Willmann19b8d902022-01-05 09:12:34 +0100675/* send RANAP on Iuh and expect it to show up on Iu */
676function f_iuh2iu(template (present) RANAP_PDU tx, template RANAP_PDU exp_rx := omit)
677runs on ConnHdlr return RANAP_PDU {
678 var RANAP_PDU rx;
679 timer T := 5.0;
680
681 if (istemplatekind(exp_rx, "omit")) {
682 exp_rx := tx;
683 }
684
685 RUA.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100686
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100687 return f_bssap_expect(exp_rx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100688}
689
690/* send RANAP on Iu and expect it to show up on Iuh */
691function f_iu2iuh(template (present) RANAP_PDU tx, template RANAP_PDU exp_rx := omit)
692runs on ConnHdlr return RANAP_PDU {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100693 if (istemplatekind(exp_rx, "omit")) {
694 exp_rx := tx;
695 }
696
697 BSSAP.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100698
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100699 return f_rua_expect(exp_rx)
700}
701
702/* expect to receive a specific RUA message on Iuh */
703private function f_rua_expect(template (present) RANAP_PDU exp_rx) runs on ConnHdlr return RANAP_PDU
704{
705 var RANAP_PDU rx;
706 timer T := 5.0;
707 T.start;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100708 alt {
709 [] RUA.receive(exp_rx) -> value rx {
710 setverdict(pass);
711 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100712 [] RUA.receive(RANAP_PDU:?) {
713 setverdict(fail, "Got an unexpected RUA message, was waiting for ", exp_rx);
714 mtc.stop;
715 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100716 [] T.timeout {
717 setverdict(fail, "Timeout waiting for Iuh ", exp_rx);
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100718 mtc.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100719 }
720 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100721 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100722 return rx;
723}
724
725/* send RANAP on Iuh and expect it to show up on Iu */
726function f_iuh2iu_connect(template (present) RANAP_PDU tx, template RANAP_PDU exp_rx := omit)
727runs on ConnHdlr return RANAP_PDU {
728 var RANAP_PDU rx;
729 timer T := 5.0;
730
731 if (istemplatekind(exp_rx, "omit")) {
732 exp_rx := tx;
733 }
734
735 /* create an expect on the Iu side for the random NAS portion */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200736 if (g_pars.expect_separate_sccp_cr) {
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200737 f_ran_register_sccp_cr_without_payload();
738 } else {
739 var template (omit) octetstring nas := f_ranap_extract_l3(valueof(tx));
740 f_ran_register_exp(valueof(nas));
741 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100742
743 /* send it via Iuh (creating a RUA connection) */
744 RUA.send(RUA_Conn_Req:{g_pars.ps_domain, tx});
745
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200746 if (g_pars.expect_separate_sccp_cr) {
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200747 /* Acknowledge the empty SCCP CR. RAN_Emulation does the confirmation, no need to respond. */
748 BSSAP.receive(tr_RANAP_Conn_Req());
749 }
750
Daniel Willmann19b8d902022-01-05 09:12:34 +0100751 /* expect to receive it on the Iu side */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100752 return f_bssap_expect(exp_rx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100753}
754
Neels Hofmeyr99b7d402023-02-20 14:26:31 +0100755/* 3GPP TS 48.006 9.2 Connection release:
756 *
757 * The MSC sends a SCCP released message. This message shall not contain
758 * any user data field.
759 *
760 * So what we expect normally is:
761 *
762 * HNBGW MSC
763 * RUA --id-Disconnect-------> | ---Data-Form-1(!)---> | Iu-ReleaseComplete
764 * | <--Released---------- | (no data)
765 *
766 * This function tests osmo-hnbgw behavior if the CN fails to send a RLSD:
767 * after some timeout, osmo-hnbgw should send a RLSD to the CN.
768 */
Daniel Willmann19b8d902022-01-05 09:12:34 +0100769function f_iuh2iu_disconnect(template (present) RANAP_PDU tx, RUA_IEs.Cause cause,
770 template RANAP_PDU exp_rx := omit)
771runs on ConnHdlr return RANAP_PDU {
772 var RANAP_PDU rx
Pau Espin Pedrolee4ce862023-11-02 12:23:25 +0100773 timer T := int2float(mp_hnbgw_timer_x31) + 1.0;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100774
775 if (istemplatekind(exp_rx, "omit")) {
776 exp_rx := tx;
777 }
778
779 /* send it via Iuh (creating a RUA connection) */
780 RUA.send(RUA_Disc_Req:{tx, cause});
781
782 /* expect to receive it on the Iu side */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100783 rx := f_bssap_expect(exp_rx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100784
785 /* expect disconnect on the Iu side */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100786 T.start;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100787 alt {
788 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
789 setverdict(pass);
790 }
791 [] T.timeout {
792 setverdict(fail, "Timeout waiting for Iu disconnect");
793 return rx;
794 }
795
796 }
797 return rx;
798}
799
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200800private function f_build_initial_ue_with_nas(TestHdlrParams pars, octetstring nas)
801 return RANAP_PDU {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100802 var LAI lai := {
803 pLMNidentity := hex2oct(pars.hnb.lai.mcc_mnc),
804 lAC := int2oct(pars.hnb.lai.lac, 2),
805 iE_Extensions := omit
806 };
807 var SAI sai := {
808 pLMNidentity := lai.pLMNidentity,
809 lAC := lai.lAC,
810 sAC := int2oct(pars.hnb.sac, 2),
811 iE_Extensions := omit
812 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100813 var IuSignallingConnectionIdentifier sigc_id := int2bit(f_rnd_int(1000), 24);
814 var GlobalRNC_ID grnc_id := {
815 pLMNidentity := lai.pLMNidentity,
816 rNC_ID := 2342
817 }
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200818 var template RANAP_PDU ret;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100819 if (pars.ps_domain) {
820 var RAC rac := '00'O;
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200821 ret := ts_RANAP_initialUE_PS(lai, rac, sai, nas, sigc_id, grnc_id);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100822 } else {
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200823 ret := ts_RANAP_initialUE_CS(lai, sai, nas, sigc_id, grnc_id);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100824 }
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200825 return valueof(ret);
826}
827
828/* build a RANAP InitialUE based on the TestHdlrParams */
829friend function f_build_initial_ue(TestHdlrParams pars) return RANAP_PDU {
830
831 var octetstring nas;
832
833 if (pars.tx_sccp_cr_data_len == 0) {
834 nas := f_rnd_octstring(10);
835 } else {
836 /* The test asks for an exact number of Optional Data bytes. */
837
838 /* First see what size the RANAP part of the payload data is,
839 * to adjust the NAS PDU size to the size requested by the test (pars.tx_sccp_cr_data_len). */
840 var RANAP_PDU initial_ue := f_build_initial_ue_with_nas(pars, '00'O);
841
842 var octetstring ranap_plus_one_byte_nas := enc_RANAP_PDU(initial_ue);
843 var integer ranap_length := lengthof(ranap_plus_one_byte_nas) - 1;
844
845 log("ranap_plus_one_byte_nas = ", lengthof(ranap_plus_one_byte_nas), " bytes, ", initial_ue, " = ",
846 ranap_plus_one_byte_nas);
847 log("ranap_length = ", ranap_length);
848
849 /* SCCP CR has a payload length limit of 130 bytes. To trigger this limit, the RANAP + NAS PDU has to be
850 * > 130 bytes. It doesn't need to be 131 bytes in the NAS PDU alone, but let's just make it definitely
851 * large enough. To test for this limit, pars.tx_sccp_cr_data_len asks for a specific amount of data len. */
852 nas := f_rnd_octstring(pars.tx_sccp_cr_data_len - ranap_length);
853 }
854
855 var RANAP_PDU ret := f_build_initial_ue_with_nas(pars, nas);
856
857 if (pars.tx_sccp_cr_data_len != 0) {
858 for (var integer attempts := 0; attempts < 2; attempts := attempts + 1) {
859 var octetstring check_len := enc_RANAP_PDU(ret);
860 log("final RANAP PDU length = ", lengthof(check_len));
861 if (lengthof(check_len) == pars.tx_sccp_cr_data_len) {
862 return ret;
863 }
864 nas := f_rnd_octstring(lengthof(nas) + (pars.tx_sccp_cr_data_len - lengthof(check_len)));
865 log("that was off, changed NAS length to ", lengthof(nas), " and trying again");
866 ret := f_build_initial_ue_with_nas(pars, nas);
867 }
868 setverdict(fail, "Ended up with wrong Optional Data length");
869 mtc.stop;
870 }
871 return ret;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100872}
873
874/* build a RANAP RAB AssignmentResponse based on the TestHdlrParams */
875friend function f_build_rab_ass_resp(TestHdlrParams pars) return RANAP_PDU {
876 var template RAB_SetupOrModifiedList rab_sml;
877
878 rab_sml := ts_RAB_SMdL(t_RAB_id(23), f_ts_RAB_TLA("192.168.1.23"), t_RAB_binding_port(1234));
879
880 return valueof(ts_RANAP_RabAssResp(rab_sml));
881}
882
883
884/***********************************************************************
885 * HNBAP Testing
886 ***********************************************************************/
887
888
Daniel Willmannc79679a2022-08-23 17:48:39 +0200889function f_hnbap_register(integer hnb_idx := 0, integer cell_id := 0, boolean expect_reject := false) runs on test_CT
Daniel Willmann19b8d902022-01-05 09:12:34 +0100890{
891 timer T := 2.0;
892
Neels Hofmeyrfffe79b2023-06-27 01:16:15 +0200893 HNBAP[hnb_idx].send(ts_HNBAP_HNBRegisterRequest(char2oct("TTCN3-HNB-" & int2str(hnb_idx)),
Daniel Willmann19b8d902022-01-05 09:12:34 +0100894 '00F110'O,
Daniel Willmannc79679a2022-08-23 17:48:39 +0200895 int2bit(1 + cell_id, 28),
Daniel Willmann19b8d902022-01-05 09:12:34 +0100896 int2oct(2, 2),
897 int2oct(3, 1),
898 int2oct(4, 2)));
899
900 T.start;
901 alt {
902 [] HNBAP[hnb_idx].receive(tr_HNBAP_HNBRegisterAccept(?)) {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200903 if (expect_reject) {
904 setverdict(fail, "Rx HNB Register Accept while expecting reject");
905 } else {
906 setverdict(pass);
907 }
908 }
909 [] HNBAP[hnb_idx].receive(tr_HNBAP_HNBRegisterReject(?)) {
910 if (expect_reject) {
911 setverdict(pass);
912 } else {
913 setverdict(fail, "Rx HNB Register Reject while expecting accept");
914 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100915 }
916 [] HNBAP[hnb_idx].receive(IUHEM_Event:?) {
917 repeat;
918 }
919 [] T.timeout {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200920 setverdict(fail, "Timeout waiting for HNB Register response");
Daniel Willmann19b8d902022-01-05 09:12:34 +0100921 }
922 }
923}
924
925testcase TC_hnb_register() runs on test_CT {
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200926 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200927 f_init(start_hnb := false);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100928 f_hnbap_register(0);
929 f_shutdown_helper();
930}
931
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200932/* Try to register the same HNB from 2 different concurrent connections. Second
933 * one should be rejected. */
Daniel Willmannc79679a2022-08-23 17:48:39 +0200934testcase TC_hnb_register_duplicate() runs on test_CT {
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200935 g_num_hnbs := 2;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200936 f_init(start_hnb := false);
Daniel Willmannc79679a2022-08-23 17:48:39 +0200937 f_hnbap_register(0);
938 f_hnbap_register(1, 0, expect_reject := true);
939 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
940 f_shutdown_helper();
941}
942
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200943/* Try to register the same HNB in the same connection already established, aka
944 * duplicate HNB Register Request. It should be accepted and new configuration
945 * applied. TS 25.469 8.2.4 */
946testcase TC_hnb_register_duplicate_reuse_sctp_assoc() runs on test_CT {
947 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200948 f_init(start_hnb := false);
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200949 f_hnbap_register(0);
950 f_hnbap_register(0);
951 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
952 f_shutdown_helper();
953}
954
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +0200955/* Drop HNBAP conn (HNBAP DEREG) and reconnect it (HNBAP REG) using same SCTP association.
956 * Related: OS#5676, SYS#6113 */
957testcase TC_hnb_reregister_reuse_sctp_assoc() runs on test_CT {
958 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200959 f_init(start_hnb := false);
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +0200960 f_hnbap_register(0);
961 HNBAP[0].send(ts_HNBAP_HNBDe_Register(ts_HnbapCause(unspecified)));
962 f_hnbap_register(0);
963 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
964 f_shutdown_helper();
965}
966
Daniel Willmann19b8d902022-01-05 09:12:34 +0100967/***********************************************************************
968 * RUA / RANAP Testing
969 ***********************************************************************/
970
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200971/* Translate from {msc,sgsn}x{0..n} to the proper index to use in g_cn[].
972 * g_cn[] stores CN links, MSCs and SGSNs in the same array.
973 * For example, for 'sgsn 23', use g_cn[ f_cn_idx(ps_domain := true, cn_nr := 23) ].
974 *
975 * Note the naming:
976 * cn_nr is the number used in the cfg file, as in 'msc 0'.
977 * cn_idx is the array index in g_cn[].
978 */
979private function f_cn_idx(boolean ps_domain, integer cn_nr := 0) return integer
980{
981 if (ps_domain) {
982 return FIRST_SGSN_IDX + cn_nr;
983 }
984 return FIRST_MSC_IDX + cn_nr;
985}
986
Daniel Willmann19b8d902022-01-05 09:12:34 +0100987private template (value) TestHdlrParams
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200988t_pars(integer imsi_suffix, boolean ps_domain := false, integer hnb_idx := 0,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200989 boolean expect_separate_sccp_cr := false, integer tx_sccp_cr_data_len := 0,
990 integer cn_nr := 0) := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100991 hnb_idx := hnb_idx,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200992 cn_idx := f_cn_idx(ps_domain, cn_nr),
Daniel Willmann19b8d902022-01-05 09:12:34 +0100993 imsi := f_gen_imsi(imsi_suffix),
994 ps_domain := ps_domain,
Pau Espin Pedrolaf746502023-11-29 16:18:28 +0100995 mgcp_pars := t_MgcpParams,
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200996 hnb := omit, /* filled in later */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200997 expect_separate_sccp_cr := expect_separate_sccp_cr,
998 tx_sccp_cr_data_len := tx_sccp_cr_data_len,
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +0200999 pfcp_local_addr := mp_pfcp_ip_local,
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02001000 nas_pdu := omit,
1001 sccp_addr_msc := omit,
1002 sccp_addr_hnbgw := omit
Daniel Willmann19b8d902022-01-05 09:12:34 +01001003}
1004
1005/* Create an Iuh connection; send InitialUE; expect it to appear on new SCCP conenction */
1006friend function f_tc_initial_ue(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1007 f_init_handler(pars);
1008 var RANAP_PDU tx := f_build_initial_ue(g_pars);
1009 f_iuh2iu_connect(tx);
1010}
1011testcase TC_ranap_cs_initial_ue() runs on test_CT {
1012 var ConnHdlr vc_conn;
1013
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001014 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001015 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001016
1017 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue), t_pars(1));
1018 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001019
1020 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001021}
1022testcase TC_ranap_ps_initial_ue() runs on test_CT {
1023 var ConnHdlr vc_conn;
1024
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001025 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001026 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001027
1028 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue), t_pars(2, true));
1029 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001030
1031 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001032}
1033
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001034private function f_vty_set_sccp_max_optional_data(TELNETasp_PT pt, integer val := -1)
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001035{
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001036 var charstring valstr;
1037 if (val < 0) {
1038 valstr := "standard";
1039 } else {
1040 valstr := int2str(val);
1041 }
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001042 f_vty_enter_config(pt);
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001043 f_vty_transceive(pt, "cs7 instance 0");
1044 f_vty_transceive(pt, "sccp max-optional-data " & valstr);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001045 f_vty_transceive(pt, "end");
1046}
1047
1048testcase TC_ranap_cs_initial_ue_empty_cr() runs on test_CT {
1049 var ConnHdlr vc_conn;
1050
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001051 g_num_hnbs := 1;
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001052 f_init();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001053
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001054 f_vty_set_sccp_max_optional_data(HNBGWVTY, 0);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001055
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001056 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 +02001057 vc_conn.done;
1058
1059 /* reset */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001060 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001061
1062 f_shutdown_helper();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001063}
1064testcase TC_ranap_ps_initial_ue_empty_cr() runs on test_CT {
1065 var ConnHdlr vc_conn;
1066
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001067 g_num_hnbs := 1;
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001068 f_init();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001069
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001070 f_vty_set_sccp_max_optional_data(HNBGWVTY, 0);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001071
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001072 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 +02001073 vc_conn.done;
1074
1075 /* reset */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001076 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001077
1078 f_shutdown_helper();
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001079}
1080
1081type record Testdata_CR_Limit {
1082 integer data_len,
1083 integer max_optional_data,
1084 boolean expect_separate_sccp_cr
1085};
1086type record of Testdata_CR_Limit Testdata_CR_Limits;
1087
1088testcase TC_sccp_cr_limit() runs on test_CT {
1089 g_num_hnbs := 1;
1090 f_init();
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001091
1092 const Testdata_CR_Limits tests := {
1093 { data_len := 130, max_optional_data := -1, expect_separate_sccp_cr := false },
1094 { data_len := 131, max_optional_data := -1, expect_separate_sccp_cr := true },
1095
1096 { data_len := 100, max_optional_data := 100, expect_separate_sccp_cr := false },
1097 { data_len := 101, max_optional_data := 100, expect_separate_sccp_cr := true },
1098
1099 { data_len := 200, max_optional_data := 200, expect_separate_sccp_cr := false },
1100 { data_len := 201, max_optional_data := 200, expect_separate_sccp_cr := true }
1101 };
1102
1103 var integer csps;
1104 for (csps := 0; csps < 2; csps := csps + 1) {
1105 var boolean ps_domain := (csps > 0);
1106
1107 var integer i;
1108 for (i := 0; i < lengthof(tests); i := i + 1) {
1109 var Testdata_CR_Limit t := tests[i];
1110 f_logp(HNBGWVTY,
1111 "TEST PART TC_sccp_cr_limit ps_domain=" & f_bool2str(ps_domain)
1112 & " data_len=" & int2str(t.data_len)
1113 & " max_optional_data=" & int2str(t.max_optional_data)
1114 & " expect_separate_sccp_cr=" & f_bool2str(t.expect_separate_sccp_cr)
1115 );
1116
1117 f_vty_set_sccp_max_optional_data(HNBGWVTY, t.max_optional_data);
1118 var ConnHdlr vc_conn;
1119 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue),
1120 t_pars(100 + i,
1121 ps_domain := ps_domain,
1122 expect_separate_sccp_cr := t.expect_separate_sccp_cr,
1123 tx_sccp_cr_data_len := t.data_len));
1124 vc_conn.done;
1125 }
1126 }
1127
1128 /* reset */
1129 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001130
1131 f_shutdown_helper();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001132}
1133
Daniel Willmann19b8d902022-01-05 09:12:34 +01001134/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1135 * Return true when an OK reply was sent, false otherwise.
1136 * Count occurrence of Osmux, include Osmux parameters in the reply if necessary. */
1137function f_handle_crcx(inout MgcpParameters pars, MgcpCommand mgcp_cmd) return template MgcpResponse {
Pau Espin Pedrol264679f2023-11-29 15:52:00 +01001138 var MgwResponse conn := pars.mgw_conn_ran;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001139 if (pars.got_crcx_count > 0) {
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001140 conn := pars.mgw_conn_cn;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001141 }
1142 pars.got_crcx_count := pars.got_crcx_count + 1;
1143
1144 var MgcpMessage mgcp_msg := {
1145 command := mgcp_cmd
1146 }
1147 var template MgcpResponse mgcp_resp;
1148 var MgcpOsmuxCID osmux_cid;
1149 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1150 if (ispresent(pars.mgcp_call_id)) {
1151 if (pars.mgcp_call_id != call_id) {
1152 setverdict(fail, "CRCX contained unexpected call id. Expected:", pars.mgcp_call_id, " got:", call_id);
1153 mtc.stop;
1154 }
1155 } else {
1156 pars.mgcp_call_id := call_id;
1157 }
1158
1159 /* When the endpoint contains a wildcard we keep the endpoint
1160 * identifier we have set up in pars. Otherwise we use the
1161 * endpoint name that the call agent has supplied */
1162 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1163 pars.mgcp_ep := mgcp_cmd.line.ep;
1164 }
1165
1166 if (conn.resp == -1) {
1167 /* Reply with rror */
1168 var MgcpResponse mgcp_rsp := {
1169 line := {
1170 code := "542",
1171 trans_id := mgcp_cmd.line.trans_id,
1172 string := "FORCED_FAIL"
1173 },
1174 sdp := omit
1175
1176 }
1177 var MgcpParameter mgcp_rsp_param := {
1178 code := "Z",
1179 val := pars.mgcp_ep
1180 };
1181 mgcp_rsp.params[0] := mgcp_rsp_param;
1182 return mgcp_rsp;
1183 }
1184
1185 if (conn.resp == 0) {
1186 /* Do not reply at all */
1187 return omit;
1188 }
1189
1190 if (conn.resp != 1) {
1191 setverdict(fail, "Unexpected value for pars.mgw_conn_*.resp, expect -1, 0 or 1");
1192 mtc.stop;
1193 }
1194
1195 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1196 hex2str(pars.mgcp_call_id), "42",
1197 conn.mgw_rtp_port,
1198 { int2str(pars.rtp_payload_type) },
1199 { valueof(ts_SDP_rtpmap(pars.rtp_payload_type,
1200 pars.rtp_sdp_format)),
1201 valueof(ts_SDP_ptime(20)) }));
1202
1203 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1204 if (not pars.use_osmux) {
1205 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1206 mtc.stop;
1207 }
1208 pars.got_osmux_count := pars.got_osmux_count + 1;
1209 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1210 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1211 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1212 if (osmux_cid != -1) {
1213 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1214 mtc.stop;
1215 }
1216
1217 osmux_cid := 0;
1218 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1219 } else {
1220 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1221 }
1222
1223 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(pars.mgcp_ep));
1224
1225 return mgcp_resp;
1226}
1227
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001228friend function f_create_rab(inout MgcpParameters pars) runs on ConnHdlr {
1229 f_rab_ass_req(pars);
1230 f_rab_ass_resp(pars);
1231}
1232
1233friend function f_rab_ass_req(inout MgcpParameters pars) runs on ConnHdlr {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001234 var MgcpCommand mgcp_cmd;
1235 var RANAP_PDU tx;
1236 var template RAB_SetupOrModifyList rab_sml;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001237 timer T := 5.0;
1238
1239 /* Send RAB Assignment Request */
1240 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));
1241 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1242 BSSAP.send(tx);
1243 T.start;
1244
1245 /* Handle MGCP CRCX */
1246 alt {
1247 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1248 log("CRCX1", mgcp_cmd);
1249 var template MgcpResponse mgcp_rsp := f_handle_crcx(pars, mgcp_cmd);
1250 MGCP.send(valueof(mgcp_rsp));
1251 }
1252 [] T.timeout {
1253 setverdict(fail, "Timeout waiting for MGCP");
1254 }
1255 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001256 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001257
1258 /* Expect RAB Assignment Request with IP/port from CRCX ACK via Iuh */
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001259 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 +01001260 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1261
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001262 f_rua_expect(tx);
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001263}
1264
1265friend function f_rab_ass_resp(inout MgcpParameters pars) runs on ConnHdlr {
1266 var MgcpCommand mgcp_cmd;
1267 var RANAP_PDU tx;
1268 var template RAB_SetupOrModifiedList rab_smdl;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001269
1270 /* Send back RAB Assignment Response via Iuh */
1271 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));
1272 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1273 RUA.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001274
1275 interleave {
1276 /* Expect MDCX with IP/port from RAB Assignment Response */
1277 [] 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 +01001278 var HostName mgw_rtp_ip;
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001279 var boolean exp_rua_rab_reass := false;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001280 log("MDCX1", mgcp_cmd);
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001281 if (ispresent(pars.mgw_conn_ran.mgw_rtp_ip_mdcx)) {
1282 mgw_rtp_ip := pars.mgw_conn_ran.mgw_rtp_ip_mdcx;
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001283 if (pars.mgw_conn_ran.mgw_rtp_ip != pars.mgw_conn_ran.mgw_rtp_ip_mdcx) {
1284 exp_rua_rab_reass := true;
1285 }
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001286 } else {
1287 mgw_rtp_ip := pars.mgw_conn_ran.mgw_rtp_ip;
1288 }
1289
Daniel Willmann19b8d902022-01-05 09:12:34 +01001290 /* Verify SDP of MDCX */
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001291 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 +01001292 { 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 +01001293 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 +01001294 MGCP.send(valueof(mgcp_rsp));
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001295
1296 /* If IP address changed, we expect HNBGW to Modify the RAB through RAB-Ass-Req: */
1297 if (exp_rua_rab_reass) {
1298 var template RAB_SetupOrModifyList rab_sml;
1299 /* Expect RAB Assignment Request with IP/port from MDCX ACK via Iuh */
1300 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));
1301 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1302
1303 f_rua_expect(tx);
1304 /* Send back RAB Assignment Response via Iuh */
1305 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));
1306 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1307 RUA.send(tx);
1308 /* This shouldn't trigger any MGCP, since nothing changed on the HNB IP side. Continue below. */
1309 }
Daniel Willmann19b8d902022-01-05 09:12:34 +01001310 }
1311 /* Handle CRCX for second leg of endpoint, answer with IP/port */
1312 [] MGCP.receive(tr_CRCX(pars.mgcp_ep, tr_SDP(pars.cn_rtp_ip, pars.cn_rtp_port))) -> value mgcp_cmd {
1313 log("CRCX2", mgcp_cmd);
1314 /* Verify SDP of CRCX */
1315 var template MgcpResponse mgcp_rsp := f_handle_crcx(pars, mgcp_cmd);
1316 MGCP.send(valueof(mgcp_rsp));
1317 }
1318 }
1319
1320 /* Expect RAB Assignment Response with IP/port from second CRCX ACK */
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001321 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 +01001322 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1323
Neels Hofmeyrdc416c92023-03-09 02:47:50 +01001324 f_bssap_expect(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001325}
1326
1327private altstep as_mgcp_dlcx(inout TestHdlrParams pars) runs on ConnHdlr {
1328 var MgcpCommand mgcp_cmd;
1329
1330 [] MGCP.receive(tr_DLCX(pars.mgcp_pars.mgcp_ep)) -> value mgcp_cmd {
1331 log("DLCX", mgcp_cmd);
1332 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1333 pars.mgcp_pars.got_dlcx_count := pars.mgcp_pars.got_dlcx_count + 1;
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001334 if (pars.mgcp_pars.got_dlcx_count != pars.mgcp_pars.got_crcx_count) {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001335 repeat;
1336 }
1337 setverdict(pass);
1338 }
1339}
1340
1341friend function f_tc_rab_assignment(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1342 var MgcpCommand mgcp_cmd;
1343 var RANAP_PDU tx;
1344 timer T := 5.0;
1345
1346 f_init_handler(pars);
1347 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1348
1349 tx := f_build_initial_ue(g_pars);
1350 f_iuh2iu_connect(tx);
1351
1352 f_create_rab(pars.mgcp_pars);
1353
1354 /* Send Iu Release */
1355 tx := valueof(ts_RANAP_IuReleaseCommand(ts_RanapCause_om_intervention));
1356 f_iu2iuh(tx);
1357
1358 T.start;
1359 alt {
1360 [] as_mgcp_dlcx(pars) {}
1361 [] T.timeout {
1362 setverdict(fail, "Timeout waiting for DLCX");
1363 }
1364 }
1365
1366 tx := valueof(ts_RANAP_IuReleaseComplete());
1367 f_iuh2iu(tx);
1368}
1369
1370testcase TC_rab_assignment() runs on test_CT {
1371 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001372 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001373 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001374
1375 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assignment), t_pars(3));
1376 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001377
1378 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001379}
1380
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001381friend function f_tc_rab_assign_fail(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1382 var MgcpCommand mgcp_cmd;
1383 var RANAP_PDU tx;
1384 timer T := 5.0;
1385
1386 f_init_handler(pars);
1387 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1388
1389 tx := f_build_initial_ue(g_pars);
1390 f_iuh2iu_connect(tx);
1391
1392 f_rab_ass_req(pars.mgcp_pars);
1393
1394 /* Send RAB failed list in response */
1395 tx := valueof(ts_RANAP_RabAssResp(rab_fl := ts_RAB_FL(t_RAB_id(23), ts_RanapCause_om_intervention)));
1396 f_iuh2iu(tx);
1397
1398 T.start;
1399 alt {
1400 [] as_mgcp_dlcx(pars) {}
1401 [] T.timeout {
1402 setverdict(fail, "Timeout waiting for DLCX");
1403 }
1404 }
1405}
1406
1407testcase TC_rab_assign_fail() runs on test_CT {
1408 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001409 g_num_hnbs := 1;
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001410 f_init();
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001411
1412 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assign_fail), t_pars(4));
1413 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001414
1415 f_shutdown_helper();
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001416}
1417
Daniel Willmann19b8d902022-01-05 09:12:34 +01001418friend function f_tc_rab_release(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1419 var MgcpCommand mgcp_cmd;
1420 var RANAP_PDU tx;
1421 timer T := 15.0;
1422
1423 f_init_handler(pars);
1424 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1425
1426 tx := f_build_initial_ue(g_pars);
1427 f_iuh2iu_connect(tx);
1428
1429 f_create_rab(pars.mgcp_pars);
1430
1431 /* Send RAB Release */
Daniel Willmann9e789be2022-02-22 13:30:51 +01001432 tx := valueof(ts_RANAP_RabAssReq(rab_rl := ts_RAB_RL(t_RAB_id(23), ts_RanapCause_om_intervention)));
Daniel Willmann19b8d902022-01-05 09:12:34 +01001433 BSSAP.send(tx);
1434
1435 T.start;
1436
1437 alt {
1438 [] as_mgcp_dlcx(pars) {}
1439 [] T.timeout {
1440 setverdict(fail, "Timeout waiting for DLCX");
1441 }
1442 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001443 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001444
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001445 f_rua_expect(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001446}
1447
1448testcase TC_rab_release() runs on test_CT {
1449 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001450 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001451 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001452
1453 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_release), t_pars(5));
1454 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001455
1456 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001457}
1458
Daniel Willmann37c877f2022-02-22 16:47:06 +01001459friend function f_tc_rab_assign_mgcp_to(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1460 var MgcpCommand mgcp_cmd;
1461 var RANAP_PDU tx;
1462 var template RAB_SetupOrModifyList rab_sml;
1463 timer T := 15.0;
1464
1465 T.start;
1466 f_init_handler(pars);
1467 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1468
1469 tx := f_build_initial_ue(g_pars);
1470 f_iuh2iu_connect(tx);
1471
1472
1473 /* Send RAB Assignment Request */
1474 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));
1475 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1476 BSSAP.send(tx);
1477
1478 /* Ignore MGCP CRCX */
1479 alt {
1480 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1481 log("Ignoreing CRCX1", mgcp_cmd);
1482 repeat;
1483 }
1484 [] BSSAP.receive(tr_RANAP_IuReleaseRequest(?)) { }
1485 [] T.timeout {
1486 setverdict(fail, "Timeout waiting for IuRelease");
1487 }
1488 }
1489
1490 /* Send Iu Release */
1491 tx := valueof(ts_RANAP_IuReleaseCommand(ts_RanapCause_om_intervention));
1492 f_iu2iuh(tx);
1493
1494 tx := valueof(ts_RANAP_IuReleaseComplete());
1495 f_iuh2iu(tx);
1496}
1497
1498testcase TC_rab_assign_mgcp_to() runs on test_CT {
1499 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001500 g_num_hnbs := 1;
Daniel Willmann37c877f2022-02-22 16:47:06 +01001501 f_init();
Daniel Willmann37c877f2022-02-22 16:47:06 +01001502
1503 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assign_mgcp_to), t_pars(6));
1504 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001505
1506 f_shutdown_helper();
Daniel Willmann37c877f2022-02-22 16:47:06 +01001507}
1508
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001509/* Test case where IuUP IP address announced by HNB and updated through MDCX
1510 * makes MGW select a new local IuUP address. HNBGW is expected to update the HNB
1511 * through RAB-Modify-Req. */
1512testcase TC_rab_assign_mgw_iuup_addr_chg() runs on test_CT {
1513 var ConnHdlr vc_conn;
1514 g_num_hnbs := 1;
1515 f_init();
1516 var template (value) TestHdlrParams pars := t_pars(3);
1517 /* Emulate change of local IuUP IP address after rx MDCX: */
1518 pars.mgcp_pars.mgw_conn_ran.mgw_rtp_ip_mdcx := "127.3.2.1";
1519
1520 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assignment), pars);
1521 vc_conn.done;
1522
1523 f_shutdown_helper();
1524}
1525
Daniel Willmann19b8d902022-01-05 09:12:34 +01001526/* Create an Iuh connection; send InitialUE; transceive data both directions */
1527friend function f_tc_ranap_bidir(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1528 f_init_handler(pars);
1529
1530 /* HNB -> MSC: InitialUE */
1531 f_iuh2iu_connect(f_build_initial_ue(g_pars));
1532
1533 /* MSC <- HNB: DirectTransfer */
1534 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1535 /* MSC -> HNB: DirectTransfer */
1536 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1537
1538 /* HNB <- MSC: CommonID */
1539 f_iu2iuh(ts_RANAP_CommonId(hex2oct(pars.imsi)));
1540}
1541testcase TC_ranap_cs_bidir() runs on test_CT {
1542 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001543 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001544 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001545
1546 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_bidir), t_pars(3));
1547 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001548
1549 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001550}
1551testcase TC_ranap_ps_bidir() runs on test_CT {
1552 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001553 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001554 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001555
1556 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_bidir), t_pars(4, true));
1557 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001558
1559 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001560}
1561
1562
1563private function f_tc_ranap_mo_disconnect(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1564 f_init_handler(pars);
1565
1566 /* HNB -> MSC: InitialUE */
1567 f_iuh2iu_connect(f_build_initial_ue(g_pars));
1568
1569 /* MSC <- HNB: DirectTransfer */
1570 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1571 /* MSC -> HNB: DirectTransfer */
1572 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1573
1574 /* MSC <- HNB: RUA disconnect */
1575 f_iuh2iu_disconnect(ts_RANAP_IuReleaseComplete, RUA_IEs.Cause:{misc:=processing_overload});
1576}
1577testcase TC_ranap_cs_mo_disconnect() runs on test_CT {
1578 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001579 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001580 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001581
1582 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_mo_disconnect), t_pars(5));
1583 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001584
1585 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001586}
1587testcase TC_ranap_ps_mo_disconnect() runs on test_CT {
1588 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001589 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001590 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001591
1592 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_mo_disconnect), t_pars(6));
1593 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001594
1595 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001596}
1597
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001598type record FTeid {
1599 HostName addr,
1600 OCT4 teid
1601}
1602
1603type record FTeids {
1604 FTeid local,
1605 FTeid remote
1606}
Daniel Willmann19b8d902022-01-05 09:12:34 +01001607
1608
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001609/* 'local' and 'remote' refer to the GTP information from the UPF's point of view:
1610 * HNB UPF CN
1611 * access.remote <---> access.local | core.local <---> core.remote
1612 */
1613type record GtpParameters {
1614 FTeids core,
1615 FTeids access
1616}
1617
1618/* HNB UPF CN
1619 * access.remote <---> access.local | core.local <---> core.remote
1620 * 127.0.0.4 127.0.0.3 127.0.0.2 127.0.0.1
1621 * 0x44004400 0x30303030 0x22002200 0x10101010
1622 */
1623template GtpParameters t_GtpParameters := {
1624 core := {
1625 local := {
1626 addr := "127.0.0.2",
1627 teid := '22002200'O
1628 },
1629 remote := {
1630 addr := "127.0.0.1",
1631 teid := '10101010'O
1632 }
1633 },
1634 access := {
1635 local := {
1636 addr := "127.0.0.3",
1637 teid := '30303030'O
1638 },
1639 remote := {
1640 addr := "127.0.0.4",
1641 teid := '44004400'O
1642 }
1643 }
1644}
1645
Neels Hofmeyr65499282023-04-25 02:31:51 +02001646private 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 +01001647{
1648 var PDU_PFCP rx;
Neels Hofmeyr65499282023-04-25 02:31:51 +02001649 timer T := wait_time;
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001650 T.start;
1651 alt {
1652 [] PFCP.receive(exp_rx) -> value rx {
1653 setverdict(pass);
1654 }
1655 [] PFCP.receive(PDU_PFCP:?) {
1656 setverdict(fail, "Got an unexpected PFCP message, was waiting for ", exp_rx);
1657 mtc.stop;
1658 }
1659 [] T.timeout {
1660 setverdict(fail, "Timeout waiting for PFCP ", exp_rx);
1661 mtc.stop;
1662 }
1663 }
1664 T.stop;
1665 return rx;
1666}
1667
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001668friend function f_tc_ps_rab_assignment_with_pfcp(charstring id, TestHdlrParams pars) runs on ConnHdlr {
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001669 var RANAP_PDU tx;
1670 var RANAP_PDU rx;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001671
1672 f_init_handler(pars);
1673
1674 f_pfcp_register();
1675
1676 var PDU_PFCP m;
1677 var Node_ID upf_node_id := valueof(ts_PFCP_Node_ID_fqdn("\07osmocom\03org"));
1678
Neels Hofmeyr65499282023-04-25 02:31:51 +02001679 m := f_pfcp_expect(tr_PFCP_Assoc_Setup_Req(), wait_time := 15.0);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001680 PFCP.send(ts_PFCP_Assoc_Setup_Resp(m.sequence_number, upf_node_id,
1681 ts_PFCP_Cause(REQUEST_ACCEPTED), 1234));
1682
1683 tx := f_build_initial_ue(g_pars);
1684 f_iuh2iu_connect(tx);
1685
1686 var GtpParameters gtp_pars := valueof(t_GtpParameters);
1687 var template RAB_SetupOrModifyList rab_sml;
1688
1689 /* Send RAB Assignment Request */
1690 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.core.remote.addr), gtp_pars.core.remote.teid);
1691 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1692 BSSAP.send(tx);
1693
1694 /* Expect PFCP Session Establishment Request. */
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001695 m := f_pfcp_expect(tr_PFCP_Session_Est_Req());
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001696 var F_SEID hnbgw_f_seid := m.message_body.pfcp_session_establishment_request.CP_F_SEID;
1697 var PFCP_Session_Establishment_Request serq := m.message_body.pfcp_session_establishment_request;
1698
1699 /* Acting as UPF, invent a new PFCP SEID to send to HNBGW. Respond to the Session Establishment.
1700 * The PFCP response must have the same sequence_number as the request. */
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001701 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 +02001702 var template PDU_PFCP r := ts_PFCP_Session_Est_Resp(m.sequence_number, upf_node_id, hnbgw_f_seid.seid);
1703 r.message_body.pfcp_session_establishment_response := {
1704 offending_ie := omit,
1705 UP_F_SEID := up_f_seid,
1706 created_PDR_list := {
1707 ts_PFCP_Created_PDR(pdr_id := serq.create_PDR_list[0].grouped_ie.pdr_id,
1708 local_F_TEID := ts_PFCP_F_TEID_ipv4(gtp_pars.core.local.teid,
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001709 f_inet_addr(gtp_pars.core.local.addr))),
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001710 ts_PFCP_Created_PDR(pdr_id := serq.create_PDR_list[1].grouped_ie.pdr_id,
1711 local_F_TEID := ts_PFCP_F_TEID_ipv4(gtp_pars.access.local.teid,
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001712 f_inet_addr(gtp_pars.access.local.addr)))
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001713 },
1714 load_control_information := omit,
1715 overload_control_information := omit,
1716 node_list := omit,
1717 failed_rule_id := omit,
1718 created_traffic_endpoint_list := omit
1719 };
1720 PFCP.send(r);
1721
1722 /* Expect on Iuh: RAB Assignment Request with IP/port from PFCP Session Est Resp */
1723 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.local.addr),
1724 gtp_pars.access.local.teid);
1725 rx := valueof(ts_RANAP_RabAssReq(rab_sml));
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001726 f_rua_expect(rx);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001727
1728 /* Send back RAB Assignment Response via Iuh */
1729 var template RAB_SetupOrModifiedList rab_smdl;
1730 rab_smdl := ts_RAB_SMdL_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.remote.addr),
1731 gtp_pars.access.remote.teid);
1732 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1733 RUA.send(tx);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001734
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001735 m := f_pfcp_expect(tr_PFCP_Session_Mod_Req(up_f_seid.seid));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001736 r := ts_PFCP_Session_Mod_Resp(m.sequence_number, hnbgw_f_seid.seid);
1737 PFCP.send(r);
1738
1739 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 +01001740 f_bssap_expect(tr_RANAP_RabAssResp(rab_smdl));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001741
1742 f_sleep(2.0);
1743 tx := valueof(ts_RANAP_IuReleaseCommand(ts_RanapCause_om_intervention));
1744 f_iu2iuh(tx);
1745
1746 tx := valueof(ts_RANAP_IuReleaseComplete());
1747 f_iuh2iu(tx);
1748
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001749 m := f_pfcp_expect(tr_PFCP_Session_Del_Req(up_f_seid.seid));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001750 PFCP.send(ts_PFCP_Session_Del_Resp(m.sequence_number, hnbgw_f_seid.seid));
1751
1752 f_sleep(2.0);
1753}
1754
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001755testcase TC_ps_rab_assignment_with_pfcp() runs on test_CT {
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001756 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001757 g_num_hnbs := 1;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001758 f_init();
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001759 f_sleep(1.0);
1760
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001761 vc_conn := f_start_handler_with_pars(refers(f_tc_ps_rab_assignment_with_pfcp), t_pars(7, ps_domain := true));
1762 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001763
1764 f_shutdown_helper();
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001765}
1766
1767altstep as_disallow_pfcp() runs on ConnHdlr {
1768 [] PFCP.receive(PDU_PFCP:?) {
1769 setverdict(fail, "Received PFCP message, but no PFCP communication expected");
1770 mtc.stop;
1771 }
1772}
1773
1774friend function f_tc_ps_rab_assignment_without_pfcp(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1775 var RANAP_PDU tx;
1776 var RANAP_PDU rx;
1777 timer T := 5.0;
1778
1779 f_init_handler(pars);
1780
1781 f_pfcp_register();
1782 activate(as_disallow_pfcp());
1783
1784 tx := f_build_initial_ue(g_pars);
1785 f_iuh2iu_connect(tx);
1786
1787 var GtpParameters gtp_pars := valueof(t_GtpParameters);
1788 var template RAB_SetupOrModifyList rab_sml;
1789
1790 /* Send RAB Assignment Request */
1791 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.core.remote.addr), gtp_pars.core.remote.teid);
1792 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1793 BSSAP.send(tx);
1794
1795 /* Expect on Iuh: unmodified RAB Assignment Request */
1796 rx := valueof(ts_RANAP_RabAssReq(rab_sml));
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001797 f_rua_expect(rx);
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001798
1799 /* Send back RAB Assignment Response via Iuh */
1800 var template RAB_SetupOrModifiedList rab_smdl;
1801 rab_smdl := ts_RAB_SMdL_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.remote.addr),
1802 gtp_pars.access.remote.teid);
1803 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1804 RUA.send(tx);
1805
1806 /* Expect on IuPS: unmodified RAB Assignment Response */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +01001807 f_bssap_expect(tr_RANAP_RabAssResp(rab_smdl));
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001808
1809 f_sleep(2.0);
1810 tx := valueof(ts_RANAP_IuReleaseCommand(ts_RanapCause_om_intervention));
1811 f_iu2iuh(tx);
1812
1813 tx := valueof(ts_RANAP_IuReleaseComplete());
1814 f_iuh2iu(tx);
1815
1816 f_sleep(2.0);
1817}
1818
1819testcase TC_ps_rab_assignment_without_pfcp() runs on test_CT {
1820 var ConnHdlr vc_conn;
1821 f_init();
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001822 f_sleep(1.0);
1823
1824 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 +02001825 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001826
1827 f_shutdown_helper();
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001828}
Daniel Willmann19b8d902022-01-05 09:12:34 +01001829
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02001830/* Default list of counters for a 'cn' entity to test the cnpool feature. */
1831const CounterNameVals counternames_cnpool := {
1832 { "cnpool:subscr:new", 0 },
1833 { "cnpool:subscr:known", 0 },
1834 { "cnpool:subscr:reattach", 0 },
1835 { "cnpool:subscr:attach_lost", 0 },
1836 { "cnpool:subscr:paged", 0 }
1837};
1838private function f_ctrs_cn_init(boolean ps_domain, integer cn_count := 0,
1839 CounterNameVals counternames := counternames_cnpool) runs on test_CT {
1840 if (ps_domain) {
1841 g_ctr_cn_node_name := "sgsn";
1842 if (cn_count == 0) {
1843 cn_count := NUM_SGSN;
1844 }
1845 } else {
1846 g_ctr_cn_node_name := "msc";
1847 if (cn_count == 0) {
1848 cn_count := NUM_MSC;
1849 }
1850 }
1851 g_ctr_cn := f_counter_name_vals_get_n(IPA_CTRL, g_ctr_cn_node_name, cn_count, counternames);
1852 log("initial " & g_ctr_cn_node_name & " rate counters: ", g_ctr_cn);
1853}
1854
1855/* f_ctrs_cn_init();
1856 * f_do_thing(on_cn := 0);
1857 * f_do_thing(on_cn := 0);
1858 * f_do_other(on_cn := 1);
1859 * f_ctrs_cn_add(0, "thing", 2);
1860 * f_ctrs_cn_add(1, "other");
1861 * f_ctrs_cn_verify();
1862 */
1863private function f_ctrs_cn_verify() runs on test_CT {
1864 log("verifying", g_ctr_cn_node_name, " rate counters: ", g_ctr_cn);
1865 f_counter_name_vals_expect_n(IPA_CTRL, g_ctr_cn_node_name, g_ctr_cn);
1866}
1867
1868/* convenience: f_ctrs_cn_add() and f_ctrs_cn_verify() in one call.
1869 * f_ctrs_cn_init();
1870 * f_do_thing(on_cn := 0);
1871 * f_do_thing(on_cn := 0);
1872 * f_do_thing(on_cn := 0);
1873 * f_ctrs_cn_expect(0, "thing", 3);
1874 */
1875private function f_ctrs_cn_expect(integer cn_nr, charstring countername, integer val := 1) runs on test_CT {
1876 f_ctrs_cn_add(cn_nr, countername, val);
1877 f_ctrs_cn_verify();
1878}
1879
1880private function f_ctrs_cn_add(integer cn_nr, charstring countername, integer val := 1) runs on test_CT {
1881 f_counter_name_vals_list_add(g_ctr_cn, cn_nr, countername, val);
1882}
1883
1884private function f_perform_compl_l3(octetstring nas, boolean do_clear := true, boolean expect_iu_l3 := true)
1885runs on ConnHdlr {
1886 timer T := 10.0;
1887
1888 /* create an expect on the Iu side for the random NAS portion */
1889 if (g_pars.expect_separate_sccp_cr) {
1890 f_ran_register_sccp_cr_without_payload();
1891 } else {
1892 f_ran_register_exp(nas);
1893 }
1894
1895 /* send Connect via Iuh (creating a RUA connection) */
1896 var RANAP_PDU tx := f_build_initial_ue_with_nas(g_pars, nas);
1897 RUA.send(RUA_Conn_Req:{g_pars.ps_domain, tx});
1898
1899 if (expect_iu_l3) {
1900 /* Expect same message to arrive at CN */
1901 f_bssap_expect(tx);
1902 }
1903}
1904
1905private function f_tc_cnpool_compl_l3(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1906 f_init_handler(pars);
1907 f_perform_compl_l3(g_pars.nas_pdu);
1908}
1909
1910private function f_TC_cnpool_compl_l3(boolean ps_domain, octetstring nas_pdu, integer cn_nr,
1911 template (omit) charstring inc_countername := omit) runs on test_CT {
1912 var ConnHdlr vc_conn;
1913 var template (value) TestHdlrParams pars := t_pars(0, ps_domain := ps_domain, cn_nr := cn_nr);
1914 pars.nas_pdu := nas_pdu;
1915 log("XXX ", pars);
1916 vc_conn := f_start_handler_with_pars(refers(f_tc_cnpool_compl_l3), pars);
1917 vc_conn.done;
1918
1919 if (not istemplatekind(inc_countername, "omit")) {
1920 f_ctrs_cn_expect(cn_nr, valueof(inc_countername));
1921 }
1922}
1923
1924function f_TC_cnpool_compl_l3_list(boolean ps_domain, ro_octetstring compl3, Osmocom_Types.ro_integer cn_nrs,
1925 charstring inc_countername) runs on test_CT {
1926 var integer n := lengthof(compl3);
1927 if (n < lengthof(cn_nrs)) {
1928 n := lengthof(cn_nrs);
1929 }
1930 for (var integer i := 0; i < n; i := i + 1) {
1931 var integer cn_nr := cn_nrs[i mod lengthof(cn_nrs)];
1932 f_TC_cnpool_compl_l3(ps_domain, compl3[i mod lengthof(compl3)], cn_nr, inc_countername);
1933 }
1934}
1935
1936type enumerated Compl3Type {
1937 /* CS */
1938 LU,
1939 CMSERV,
1940 PAGRESP,
1941 IMSIDETACH,
1942
1943 /* PS */
1944 ATTACHREQ,
1945 RAUREQ,
1946 DETREQ
1947};
1948
1949private function f_gen_one_compl_l3(Compl3Type compl3type, template (value) MobileIdentityLV mi,
1950 integer ps_nri := -1
1951 ) return octetstring
1952{
1953 /* CS */
1954 if (compl3type == LU) {
1955 return enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(mi), '00F110'O)));
1956 }
1957 if (compl3type == CMSERV) {
1958 return enc_PDU_ML3_MS_NW(valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(mi))));
1959 }
1960 if (compl3type == PAGRESP) {
1961 return enc_PDU_ML3_MS_NW(valueof(ts_PAG_RESP(valueof(mi))));
1962 }
1963 if (compl3type == IMSIDETACH) {
1964 return enc_PDU_ML3_MS_NW(valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(mi))));
1965 }
1966
1967 /* PS */
1968 var template (omit) NetworkResourceIdentifierContainerTLV nri := omit;
1969 if (ps_nri >= 0) {
1970 nri := valueof(ts_GMM_NRI(ps_nri));
1971 }
1972
1973 if (compl3type == ATTACHREQ) {
1974 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_ATTACH_REQ(valueof(mi), f_RAI('001'H, '01'H, '2a2a'O, '17'O),
1975 nri := nri)));
1976 }
1977 if (compl3type == RAUREQ) {
1978 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_RAU_REQ(valueof(mi), GPRS_UPD_T_PERIODIC,
1979 f_RAI('001'H, '01'H, '2a2a'O, '17'O),
1980 nri := nri)));
1981 }
1982 if (compl3type == DETREQ) {
1983 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_DET_REQ_MO_mi(c_GMM_DTT_MO_GPRS, power_off := false,
1984 p_tmsi := valueof(ts_MI_TLV(mi.mobileIdentityV)))));
1985 }
1986
1987 setverdict(fail, "unknown complete layer 3 type");
1988 mtc.stop;
1989}
1990
1991type record of Compl3Type ro_Compl3Type;
1992type record of MobileIdentityLV ro_MobileIdentityLV;
1993type record of octetstring ro_octetstring;
1994
1995/* Generate a list of n Complete Layer 3 NAS PDUs,
1996 * rotating through the message kinds listed in 'types' and the mobile identities in mis.
1997 */
1998private function f_gen_compl_l3(ro_Compl3Type types, ro_MobileIdentityLV mis, integer n) return ro_octetstring
1999{
2000 var ro_octetstring res := {};
2001 for (var integer i := 0; i < n; i := i + 1) {
2002 var integer ti := i mod lengthof(types);
2003 var integer mi := i mod lengthof(mis);
2004 res[i] := f_gen_one_compl_l3(types[ti], mis[mi]);
2005 }
2006 return res;
2007}
2008
2009private function f_gen_mi_imsi(integer n) return MobileIdentityLV
2010{
2011 return valueof(ts_MI_IMSI_LV(f_gen_imsi(n)));
2012}
2013
2014private function f_gen_mi_imsis(integer n) return ro_MobileIdentityLV
2015{
2016 var ro_MobileIdentityLV mis := {};
2017 for (var integer i := 0; i < n; i := i + 1) {
2018 mis[i] := f_gen_mi_imsi(n);
2019 }
2020 return mis;
2021}
2022
2023function f_vty_set_roundrobin_next(TELNETasp_PT VTY, boolean ps_domain, integer cn_nr)
2024{
2025 var charstring msc_sgsn;
2026 if (ps_domain) {
2027 msc_sgsn := "sgsn";
2028 } else {
2029 msc_sgsn := "msc";
2030 }
2031 f_vty_transceive(VTY, "cnpool roundrobin next " & msc_sgsn & " " & int2str(cn_nr));
2032}
2033
2034private function f_gen_compl3_by_domain(boolean ps_domain, integer n, template (omit) ro_MobileIdentityLV mis := omit) return ro_octetstring{
2035 var ro_Compl3Type types;
2036 if (ps_domain) {
2037 types := { ATTACHREQ, RAUREQ, DETREQ };
2038 } else {
2039 types := { LU, CMSERV, PAGRESP, IMSIDETACH };
2040 }
2041 if (istemplatekind(mis, "omit")) {
2042 mis := f_gen_mi_imsis(n);
2043 }
2044 return f_gen_compl_l3(types, valueof(mis), n);
2045}
2046
2047/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
2048testcase TC_mscpool_L3Compl_on_1_cnlink() runs on test_CT {
2049 f_TC_cnpool_L3Compl_on_1_cnlink(ps_domain := false);
2050}
2051testcase TC_sgsnpool_L3Compl_on_1_cnlink() runs on test_CT {
2052 f_TC_cnpool_L3Compl_on_1_cnlink(ps_domain := true);
2053}
2054function f_TC_cnpool_L3Compl_on_1_cnlink(boolean ps_domain) runs on test_CT {
2055
2056 f_init();
2057
2058 f_ctrs_cn_init(ps_domain := ps_domain);
2059
2060 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 4);
2061 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {0, 0, 0, 0}, "cnpool:subscr:new");
2062
2063 f_shutdown_helper();
2064}
2065
2066/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
2067testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
2068 f_TC_cnpool_L3Complete_by_imsi_round_robin(ps_domain := false);
2069}
2070testcase TC_sgsnpool_L3Complete_no_nri_round_robin() runs on test_CT {
2071 f_TC_cnpool_L3Complete_by_imsi_round_robin(ps_domain := true);
2072}
2073function f_TC_cnpool_L3Complete_by_imsi_round_robin(boolean ps_domain) runs on test_CT {
2074
2075 f_init(nr_msc := 2, nr_sgsn := 2);
2076 f_sleep(1.0);
2077
2078 /* Control which MSC gets chosen next by the round-robin, otherwise
2079 * would be randomly affected by which other tests ran before this. */
2080 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2081
2082 f_ctrs_cn_init(ps_domain := ps_domain);
2083
2084 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2085
2086 f_TC_cnpool_compl_l3_list(ps_domain, compl3,
2087 /* Third Complete Layer 3 wraps back to msc 0 */
2088 cn_nrs := {0, 1, 0},
2089 inc_countername := "cnpool:subscr:new");
2090
2091 f_shutdown_helper();
2092}
2093
2094/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain a NULL-NRI (0, 1)
2095 * (configured in osmo-hnbgw.cfg). */
2096testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
2097 f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(ps_domain := false, nri_val := 0);
2098}
2099/* 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
2100 * than that. */
2101testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
2102 f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(ps_domain := false, nri_val := 1);
2103}
2104function f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(boolean ps_domain, integer nri_val) runs on test_CT {
2105
2106 f_init(nr_msc := 2, nr_sgsn := 2);
2107 f_sleep(1.0);
2108
2109 /* Control which MSC gets chosen next by the round-robin, otherwise
2110 * would be randomly affected by which other tests ran before this. */
2111 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2112
2113 f_ctrs_cn_init(ps_domain := ps_domain);
2114
2115 var ro_MobileIdentityLV mis := { valueof(ts_MI_TMSI_NRI_LV(nri_val)) };
2116 var ro_octetstring compl3;
2117 if (ps_domain) {
2118 compl3 := {
2119 f_gen_one_compl_l3(ATTACHREQ, mis[0], nri_val)
2120 };
2121 } else {
2122 compl3 := f_gen_compl_l3({LU}, mis, 1);
2123 }
2124
2125 f_TC_cnpool_compl_l3_list(ps_domain, compl3,
2126 /* The third Complete Layer 3 wraps back to msc 0 */
2127 {0, 1, 0},
2128 "cnpool:subscr:reattach");
2129 f_shutdown_helper();
2130}
2131
2132/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
2133 * assigned to any MSC (configured in osmo-hnbgw.cfg). */
2134testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
2135 f_TC_cnpool_L3Complete_by_tmsi_unassigned_nri_round_robin(ps_domain := false);
2136}
2137function f_TC_cnpool_L3Complete_by_tmsi_unassigned_nri_round_robin(boolean ps_domain) runs on test_CT {
2138
2139 f_init(nr_msc := 2, nr_sgsn := 2);
2140 f_sleep(1.0);
2141
2142 /* Control which MSC gets chosen next by the round-robin, otherwise
2143 * would be randomly affected by which other tests ran before this. */
2144 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2145
2146 f_ctrs_cn_init(ps_domain := ps_domain);
2147
2148 /* 3 NRIs that are not assigned to any MSC */
2149 var ro_MobileIdentityLV mis := {
2150 valueof(ts_MI_TMSI_NRI_LV(1000)),
2151 valueof(ts_MI_TMSI_NRI_LV(768)),
2152 valueof(ts_MI_TMSI_NRI_LV(819))
2153 };
2154
2155 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2156 f_TC_cnpool_compl_l3_list(ps_domain, compl3, { 0, 1, 0 }, "cnpool:subscr:new");
2157
2158 f_shutdown_helper();
2159}
2160
2161/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
2162 * assigned to a CN link that is currently not connected (configured in osmo-hnbgw.cfg). */
2163testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
2164 f_TC_cnpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin(ps_domain := false);
2165}
2166function f_TC_cnpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin(boolean ps_domain) runs on test_CT {
2167
2168 f_init(nr_msc := 2, nr_sgsn := 2);
2169 f_sleep(1.0);
2170
2171 /* Control which MSC gets chosen next by the round-robin, otherwise
2172 * would be randomly affected by which other tests ran before this. */
2173 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2174
2175 f_ctrs_cn_init(ps_domain := ps_domain);
2176
2177 /* 3 NRIs that are assigned to an unconnected MSC */
2178 var ro_MobileIdentityLV mis := {
2179 valueof(ts_MI_TMSI_NRI_LV(512)),
2180 valueof(ts_MI_TMSI_NRI_LV(767)),
2181 valueof(ts_MI_TMSI_NRI_LV(750))
2182 };
2183
2184 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2185
2186 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0);
2187 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2188 f_ctrs_cn_add(0, "cnpool:subscr:new");
2189 f_ctrs_cn_verify();
2190
2191 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 1);
2192 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2193 f_ctrs_cn_add(1, "cnpool:subscr:new");
2194 f_ctrs_cn_verify();
2195
2196 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 0);
2197 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2198 f_ctrs_cn_add(0, "cnpool:subscr:new");
2199 f_ctrs_cn_verify();
2200
2201 f_shutdown_helper();
2202}
2203
2204/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
2205 * osmo-hnbgw.cfg). */
2206testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
2207 f_TC_cnpool_L3Complete_valid_nri_1(ps_domain := false);
2208}
2209testcase TC_sgsnpool_L3Complete_valid_nri_1() runs on test_CT {
2210 f_TC_cnpool_L3Complete_valid_nri_1(ps_domain := true);
2211}
2212function f_TC_cnpool_L3Complete_valid_nri_1(boolean ps_domain) runs on test_CT {
2213
2214 f_init(nr_msc := 2, nr_sgsn := 2);
2215 f_sleep(1.0);
2216
2217 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
2218 * this is not using round-robin. */
2219 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2220
2221 f_ctrs_cn_init(ps_domain := ps_domain);
2222
2223 var ro_octetstring compl3;
2224
2225 /* 3 NRIs of the second MSC's range (256-511) */
2226 var ro_MobileIdentityLV mis := {
2227 valueof(ts_MI_TMSI_NRI_LV(256)),
2228 valueof(ts_MI_TMSI_NRI_LV(260)),
2229 valueof(ts_MI_TMSI_NRI_LV(511))
2230 };
2231 if (ps_domain) {
2232 compl3 := {
2233 f_gen_one_compl_l3(RAUREQ, mis[0], 256),
2234 f_gen_one_compl_l3(RAUREQ, mis[1], 260),
2235 f_gen_one_compl_l3(RAUREQ, mis[2], 511)
2236 };
2237 } else {
2238 compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2239 }
2240
2241 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {1, 1, 1}, "cnpool:subscr:known");
2242
2243 f_shutdown_helper();
2244}
2245
2246/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-hnbgw.cfg),
2247 * while a round-robin remains unaffected by that. */
2248testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
2249 f_TC_cnpool_L3Complete_valid_nri_2(ps_domain := false);
2250}
2251testcase TC_sgsnpool_L3Complete_valid_nri_2() runs on test_CT {
2252 f_TC_cnpool_L3Complete_valid_nri_2(ps_domain := true);
2253}
2254function f_TC_cnpool_L3Complete_valid_nri_2(boolean ps_domain) runs on test_CT {
2255
2256 f_init(nr_msc := 3, nr_sgsn := 3);
2257 f_sleep(1.0);
2258
2259 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
2260 * this is not using round-robin. */
2261 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 1);
2262
2263 f_ctrs_cn_init(ps_domain := ps_domain);
2264
2265 var ro_octetstring compl3;
2266
2267 /* 2 NRIs of the third MSC's range (512-767) */
2268 var ro_MobileIdentityLV mis := {
2269 valueof(ts_MI_TMSI_NRI_LV(512)),
2270 valueof(ts_MI_TMSI_NRI_LV(678))
2271 };
2272 if (ps_domain) {
2273 compl3 := {
2274 f_gen_one_compl_l3(ATTACHREQ, mis[0], 512),
2275 f_gen_one_compl_l3(ATTACHREQ, mis[1], 678)
2276 };
2277 } else {
2278 compl3 := f_gen_compl3_by_domain(ps_domain, 2, mis);
2279 }
2280
2281 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {2, 2}, "cnpool:subscr:known");
2282
2283 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
2284 f_TC_cnpool_compl_l3_list(ps_domain, f_gen_compl3_by_domain(ps_domain, 1), {1}, "cnpool:subscr:new");
2285
2286 f_shutdown_helper();
2287}
2288
2289/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
2290testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
2291 f_TC_cnpool_nri_from_other_PLMN(ps_domain := false);
2292}
2293testcase TC_sgsnpool_nri_from_other_PLMN() runs on test_CT {
2294 f_TC_cnpool_nri_from_other_PLMN(ps_domain := true);
2295}
2296function f_TC_cnpool_nri_from_other_PLMN(boolean ps_domain) runs on test_CT {
2297
2298 f_init(nr_msc := 3, nr_sgsn := 3);
2299 f_sleep(1.0);
2300
2301 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
2302 * instead, and hits msc 0. */
2303 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2304
2305 f_ctrs_cn_init(ps_domain := ps_domain);
2306
2307 var ro_octetstring compl3;
2308
2309 var ro_MobileIdentityLV mis := {
2310 valueof(ts_MI_TMSI_NRI_LV(260)),
2311 valueof(ts_MI_TMSI_NRI_LV(555))
2312 };
2313 if (ps_domain) {
2314 compl3 := {
2315 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-hnbgw.cfg */
2316 enc_PDU_L3_MS_SGSN(valueof(ts_GMM_ATTACH_REQ(mis[0], f_RAI('999'H, '99'H, '2a2a'O,
2317 '17'O),
2318 nri := ts_GMM_NRI(260)
2319 ))),
2320 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
2321 f_gen_one_compl_l3(ATTACHREQ, mis[1], 555)
2322 }
2323 } else {
2324 compl3 := {
2325 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-hnbgw.cfg */
2326 enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, mis[0], '99F999'O))),
2327 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
2328 enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, mis[1], '00F110'O)))
2329 };
2330 }
2331
2332 /* Foreign NRI: roundrobin */
2333 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2334
2335 /* Local NRI: matching msc */
2336 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 2, inc_countername := "cnpool:subscr:known");
2337
2338 f_shutdown_helper();
2339}
2340
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02002341/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
2342 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
2343friend function f_tc_mscpool_paging_imsi(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2344 f_init_handler(pars);
2345
2346 var hexstring imsi := '001010000000123'H;
2347 var RANAP_IEs.CN_DomainIndicator domain_ind;
2348 if (pars.ps_domain) {
2349 domain_ind := ps_domain;
2350 } else {
2351 domain_ind := cs_domain;
2352 }
2353 var template (value) RANAP_PDU paging := ts_RANAP_Paging(domain_ind, imsi_hex2oct(imsi));
2354 BSSAP.send(ts_RANAP_UNITDATA_req(pars.sccp_addr_hnbgw, pars.sccp_addr_msc, paging));
2355 /* TODO: Expect RUA ConnectionlessTransfer Paging (on all HNB).
2356 * We could verify the Paging sent from osmo-hnbgw to RUA with some effort,
2357 * but, this test does not care whether the Paging was forwarded to RUA or not, only that osmo-hnbgw *received*
2358 * the Paging. In the CN pool decisions, osmo-hnbgw should match up Paging Response to an earlier Paging.
2359 */
2360
2361 f_sleep(1.0);
2362
2363 /* Despite the round robin pointing at the second MSC ('roundrobin next msc 1'), the earlier Paging for the same IMSI
2364 * causes this Paging Response to go to the first MSC ('msc 0'). */
2365 f_perform_compl_l3(f_gen_one_compl_l3(PAGRESP, ts_MI_IMSI_LV(imsi)));
2366 f_sleep(1.0);
2367}
2368
2369testcase TC_mscpool_paging_imsi() runs on test_CT {
2370 f_init(nr_msc := 3);
2371 f_sleep(1.0);
2372
2373 var boolean ps_domain := false;
2374
2375 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
2376 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
2377 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2378
2379 f_ctrs_cn_init(ps_domain := ps_domain);
2380
2381 var ConnHdlr vc_conn1;
2382 var template (value) TestHdlrParams pars1 := t_pars(0, ps_domain := ps_domain, cn_nr := 0);
2383 pars1.sccp_addr_hnbgw := g_cn[valueof(pars1.cn_idx)].sccp_addr_peer;
2384 pars1.sccp_addr_msc := g_cn[valueof(pars1.cn_idx)].sccp_addr_own;
2385 vc_conn1 := f_start_handler_with_pars(refers(f_tc_mscpool_paging_imsi), pars1);
2386 vc_conn1.done;
2387 f_ctrs_cn_expect(0, "cnpool:subscr:paged");
2388 f_shutdown_helper();
2389}
2390
2391/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
2392 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
2393friend function f_tc_mscpool_paging_tmsi(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2394 f_init_handler(pars);
2395
2396 var hexstring imsi := '001010000000124'H;
2397 var integer nri_v := 300; /* <-- second MSC's NRI */
2398 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
2399
2400 var RANAP_IEs.CN_DomainIndicator domain_ind;
2401 if (pars.ps_domain) {
2402 domain_ind := ps_domain;
2403 } else {
2404 domain_ind := cs_domain;
2405 }
2406 var template (value) RANAP_PDU paging := ts_RANAP_Paging_temp_id(domain_ind, imsi_hex2oct(imsi),
2407 ts_RANAP_TemporaryUE_ID_TMSI(tmsi));
2408 BSSAP.send(ts_RANAP_UNITDATA_req(pars.sccp_addr_hnbgw, pars.sccp_addr_msc, paging));
2409 /* TODO: Expect RUA ConnectionlessTransfer Paging (on all HNB).
2410 * We could verify the Paging sent from osmo-hnbgw to RUA with some effort,
2411 * but, this test does not care whether the Paging was forwarded to RUA or not, only that osmo-hnbgw *received*
2412 * the Paging. In the CN pool decisions, osmo-hnbgw should match up Paging Response to an earlier Paging.
2413 */
2414
2415 f_sleep(1.0);
2416
2417 /* Despite the round robin pointing at the third MSC ('roundrobin next msc 2'), the earlier Paging for the same
2418 * TMSI causes this Paging Response to go to the first MSC ('msc 0'). */
2419 f_perform_compl_l3(f_gen_one_compl_l3(PAGRESP, ts_MI_TMSI_NRI_LV(nri_v)));
2420 f_sleep(1.0);
2421}
2422testcase TC_mscpool_paging_tmsi() runs on test_CT {
2423 f_init(nr_msc := 3);
2424 f_sleep(1.0);
2425
2426 var boolean ps_domain := false;
2427
2428 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
2429 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
2430 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2431
2432 f_ctrs_cn_init(ps_domain := ps_domain);
2433
2434 var ConnHdlr vc_conn1;
2435 var template (value) TestHdlrParams pars1 := t_pars(0, ps_domain := ps_domain, cn_nr := 0);
2436 pars1.sccp_addr_hnbgw := g_cn[valueof(pars1.cn_idx)].sccp_addr_peer;
2437 pars1.sccp_addr_msc := g_cn[valueof(pars1.cn_idx)].sccp_addr_own;
2438 vc_conn1 := f_start_handler_with_pars(refers(f_tc_mscpool_paging_tmsi), pars1);
2439 vc_conn1.done;
2440 f_ctrs_cn_expect(0, "cnpool:subscr:paged");
2441 f_shutdown_helper();
2442}
2443
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002444/* For round-robin, skip a CN link that has 'no allow-attach' set. */
2445testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
2446
2447 f_init(nr_msc := 3);
2448 f_sleep(1.0);
2449
2450 var boolean ps_domain := false;
2451
2452 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
2453 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, {true, false, true});
2454
2455 /* Control which MSC gets chosen next by the round-robin, otherwise
2456 * would be randomly affected by which other tests ran before this. */
2457 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2458
2459 f_ctrs_cn_init(ps_domain := ps_domain);
2460
2461 f_TC_cnpool_compl_l3_list(ps_domain, f_gen_compl3_by_domain(ps_domain, 3),
2462 /* msc 1 is skipped */
2463 {0, 2, 0},
2464 "cnpool:subscr:new");
2465
2466 f_shutdown_helper();
2467}
2468
2469/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
2470 * TMSI NRI. */
2471testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
2472
2473 f_init(nr_msc := 3);
2474 f_sleep(1.0);
2475
2476 var boolean ps_domain := false;
2477
2478 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
2479 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, {true, false, true});
2480
2481 /* Control which MSC gets chosen next by the round-robin, otherwise
2482 * would be randomly affected by which other tests ran before this. */
2483 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2484
2485 f_ctrs_cn_init(ps_domain := ps_domain);
2486
2487 var ro_MobileIdentityLV mis := {
2488 valueof(ts_MI_TMSI_NRI_LV(260)),
2489 valueof(ts_MI_IMSI_LV('001010000000002'H)),
2490 valueof(ts_MI_IMSI_LV('001010000000003'H))
2491 };
2492
2493 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2494
2495 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
2496 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 1, inc_countername := "cnpool:subscr:known");
2497
2498 /* Normal round robin skips msc 1, because it has 'no allow-attach' */
2499 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2500 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 2, inc_countername := "cnpool:subscr:new");
2501
2502 f_shutdown_helper();
2503}
2504
2505/* When a peer point-code gets an SCCP N-PCSTATE saying it is unreachable, immediately mark the CN link as unusable. */
2506testcase TC_mscpool_sccp_n_pcstate_detaches_cnlink() runs on test_CT {
2507 f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(ps_domain := false);
2508}
2509testcase TC_sgsnpool_sccp_n_pcstate_detaches_cnlink() runs on test_CT {
2510 f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(ps_domain := true);
2511}
2512function f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(boolean ps_domain) runs on test_CT
2513{
2514
2515 f_init(nr_msc := 2, nr_sgsn := 2);
2516 f_sleep(1.0);
2517
2518 /* Control which MSC gets chosen next by the round-robin, otherwise
2519 * would be randomly affected by which other tests ran before this. */
2520 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2521
2522 f_ctrs_cn_init(ps_domain := ps_domain);
2523
2524 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2525
2526 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2527 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2528
2529 f_logp(HNBGWVTY, "disconnecting msc0");
2530 f_cn_idx_disconnect(f_cn_idx(ps_domain, 0));
2531
2532 /* Now round-robin would wrap to the first MSC, but since the first MSC is disconnected, it wraps around to the
2533 * second. */
2534 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2535
2536 f_shutdown_helper();
2537}
2538
2539/* When a CN link point-code gets an SCCP N-PCSTATE saying it is now reachable, immediately trigger RESET and bring up the
2540 * MSC. */
2541testcase TC_mscpool_sccp_n_pcstate_attaches_cnlink() runs on test_CT {
2542 f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(ps_domain := false);
2543}
2544testcase TC_sgsnpool_sccp_n_pcstate_attaches_cnlink() runs on test_CT {
2545 f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(ps_domain := true);
2546}
2547function f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(boolean ps_domain) runs on test_CT
2548{
2549 f_init(nr_msc := 1, nr_sgsn := 1);
2550 f_sleep(1.0);
2551
2552 /* Control which MSC gets chosen next by the round-robin, otherwise
2553 * would be randomly affected by which other tests ran before this. */
2554 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2555
2556 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2557
2558 f_ctrs_cn_init(ps_domain := ps_domain);
2559
2560 /* There is only one MSC, round robin stays on msc0 */
2561 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2562 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[1], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2563
2564 f_logp(HNBGWVTY, "connecting cnlink 1");
2565 f_cn_nr_init(ps_domain, 1);
2566 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, { true, true });
2567 f_sleep(1.0);
2568
2569 /* This time round-robin wraps to the second MSC, because it is now online. */
2570 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[2], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2571
2572 f_shutdown_helper();
2573}
2574
Neels Hofmeyrd019cc02023-06-02 16:31:23 +02002575private function f_vty_add_sccp_addr(TELNETasp_PT pt, charstring addr_name, charstring pc, integer cs7_nr := 0)
2576{
2577 f_vty_enter_config(pt);
2578 f_vty_transceive(pt, "cs7 instance 0");
2579 f_vty_transceive(pt, "sccp-address " & addr_name);
2580 f_vty_transceive(pt, "point-code " & pc);
2581 f_vty_transceive(pt, "end");
2582}
2583
2584private function f_vty_set_cnlink_addr(TELNETasp_PT pt, charstring cnlink_and_nr, charstring addr_name)
2585{
2586 f_vty_enter_config(pt);
2587 f_vty_transceive(pt, cnlink_and_nr);
2588 f_vty_transceive(pt, "remote-addr " & addr_name);
2589 f_vty_transceive(pt, "end");
2590}
2591
2592private function f_vty_apply_sccp(TELNETasp_PT pt)
2593{
2594 f_vty_enter_config(pt);
2595 f_vty_transceive(pt, "apply sccp");
2596 f_vty_transceive(pt, "end");
2597}
2598
2599template (present) RUA_Disc_Req tr_RUA_Disc_Req := {
2600 ranap := ?,
2601 cause := ?
2602};
2603
2604/* With a cnlink up, change the SCCP address, and verify that it restarts upon vty 'apply sccp' */
2605private function f_tc_apply_sccp(charstring id, TestHdlrParams pars) runs on ConnHdlr
2606{
2607 f_init_handler(pars);
2608 f_perform_compl_l3(f_gen_compl3_by_domain(pars.ps_domain, 1)[0]);
2609
2610 f_sleep(1.0);
2611 f_logp(HNBGWVTY, "Changing SCCP address, don't apply yet");
2612
2613 f_vty_add_sccp_addr(HNBGWVTY, "msc-foo", "0.42.4");
2614 f_vty_set_cnlink_addr(HNBGWVTY, "msc 0", "msc-foo");
2615
2616 /* No effect yet, link still open both ways */
2617 f_sleep(1.0);
2618 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
2619 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
2620
2621 f_logp(HNBGWVTY, "Apply SCCP address changes");
2622 f_vty_apply_sccp(HNBGWVTY);
2623
2624 /* We modified the SCCP configuration, expect disconnect of UE that was active on the aborted link. */
2625 RUA.receive(RUA_Disc_Ind:?);
2626 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
2627
2628 /* Would be nice to test reconnection on the other point-code, too. That would require another cnlink in
2629 * osmo-stp.cfg and module parameters... */
2630
2631 f_sleep(1.0);
2632}
2633testcase TC_apply_sccp() runs on test_CT
2634{
2635 f_init();
2636 f_sleep(1.0);
2637
2638 var ConnHdlr vc_conn;
2639 var template (value) TestHdlrParams pars := t_pars(0);
2640 vc_conn := f_start_handler_with_pars(refers(f_tc_apply_sccp), pars);
2641 vc_conn.done;
2642
2643 f_shutdown_helper();
2644}
2645
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002646/* In the field, we encountered a "normal" RAB Assignment that concludes successfully, followed by another RAB
2647 * Assignment that has different SDU subflow parameters, and does not contain RTP information. At the time of writing,
2648 * it seems that the second RAB Assignment causes a crash. Play through this scenario. */
2649friend function f_tc_second_rab_assignment(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2650 var MgcpCommand mgcp_cmd;
2651 var RANAP_PDU tx;
2652 timer T := 5.0;
2653
2654 f_init_handler(pars);
2655 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
2656
2657 tx := f_build_initial_ue(g_pars);
2658 f_iuh2iu_connect(tx);
2659
2660 f_create_rab(pars.mgcp_pars);
2661
2662 /* Now send a second RAB Assignment with different subflows and omitting transportLayerInformation. (Assuming
2663 * the first RAB Assignment's transportLayerInformation remains in use unchanged.) */
2664 var template RAB_SetupOrModifyList rab_sml;
2665 rab_sml := ts_RAB_SML2(t_RAB_id(23),
2666 ts_RabParams,
2667 user_plane_info := omit,
2668 transport_layer_info := omit);
2669 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
2670 BSSAP.send(tx);
2671 T.start;
2672
2673 /* Expect this secondary RAB Assignment to go through unchanged. */
2674 f_rua_expect(tx);
2675
2676 /* I'm guessing that the RAB Assignment Response also omits transportLayerInformation, so far not known because
2677 * osmo-hnbgw crashed before we could receive the response. */
2678
2679 /* Send back RAB Assignment Response via Iuh */
2680 var template RAB_SetupOrModifiedList rab_smdl;
2681 rab_smdl := ts_RAB_SMdL_no_tla(t_RAB_id(23));
2682 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
2683 RUA.send(tx);
2684 f_bssap_expect(tx);
2685
2686 /* Send Iu Release */
2687 tx := valueof(ts_RANAP_IuReleaseCommand(ts_RanapCause_om_intervention));
2688 f_iu2iuh(tx);
2689
2690 T.start;
2691 alt {
2692 [] as_mgcp_dlcx(pars) {}
2693 [] T.timeout {
2694 setverdict(fail, "Timeout waiting for DLCX");
2695 }
2696 }
2697
2698 tx := valueof(ts_RANAP_IuReleaseComplete());
2699 f_iuh2iu(tx);
2700}
2701
2702testcase TC_second_rab_assignment() runs on test_CT {
2703 var ConnHdlr vc_conn;
2704 g_num_hnbs := 1;
2705 f_init();
2706
2707 vc_conn := f_start_handler_with_pars(refers(f_tc_second_rab_assignment), t_pars(3));
2708 vc_conn.done;
2709
2710 f_shutdown_helper();
2711}
2712
Daniel Willmann19b8d902022-01-05 09:12:34 +01002713control {
2714 execute(TC_hnb_register());
Daniel Willmannc79679a2022-08-23 17:48:39 +02002715 execute(TC_hnb_register_duplicate());
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +02002716 execute(TC_hnb_register_duplicate_reuse_sctp_assoc());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002717 execute(TC_ranap_cs_initial_ue());
2718 execute(TC_ranap_ps_initial_ue());
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02002719 execute(TC_ranap_cs_initial_ue_empty_cr());
2720 execute(TC_ranap_ps_initial_ue_empty_cr());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002721 execute(TC_ranap_cs_bidir());
2722 execute(TC_ranap_ps_bidir());
2723 execute(TC_rab_assignment());
2724 execute(TC_rab_release());
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01002725 execute(TC_rab_assign_fail());
Daniel Willmann37c877f2022-02-22 16:47:06 +01002726 execute(TC_rab_assign_mgcp_to());
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01002727 execute(TC_rab_assign_mgw_iuup_addr_chg());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002728 execute(TC_ranap_cs_mo_disconnect());
2729 execute(TC_ranap_ps_mo_disconnect());
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02002730
2731 if (mp_enable_pfcp_tests) {
2732 execute(TC_ps_rab_assignment_with_pfcp());
2733 } else {
2734 execute(TC_ps_rab_assignment_without_pfcp());
2735 }
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02002736
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002737 execute( TC_mscpool_L3Compl_on_1_cnlink() );
2738 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
2739 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
2740 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
2741 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
2742 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
2743 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
2744 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
2745 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02002746 execute( TC_mscpool_paging_imsi() );
2747 execute( TC_mscpool_paging_tmsi() );
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002748 execute( TC_mscpool_no_allow_attach_round_robin() );
2749 execute( TC_mscpool_no_allow_attach_valid_nri() );
2750 execute( TC_mscpool_sccp_n_pcstate_detaches_cnlink() );
2751 execute( TC_mscpool_sccp_n_pcstate_attaches_cnlink() );
2752
2753 execute( TC_sgsnpool_L3Compl_on_1_cnlink() );
2754 execute( TC_sgsnpool_L3Complete_no_nri_round_robin() );
2755 execute( TC_sgsnpool_L3Complete_valid_nri_1() );
2756 execute( TC_sgsnpool_L3Complete_valid_nri_2() );
2757 execute( TC_sgsnpool_nri_from_other_PLMN() );
2758 execute( TC_sgsnpool_sccp_n_pcstate_detaches_cnlink() );
2759 execute( TC_sgsnpool_sccp_n_pcstate_attaches_cnlink() );
2760
Oliver Smithaa919b42023-11-14 11:30:55 +01002761 /* Run only on nightly since it makes osmo-hnbgw <= 1.5.0 crash: OS#6253 */
2762 if (f_osmo_repo_is("nightly")) {
2763 execute(TC_second_rab_assignment());
2764 }
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002765
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02002766 /* Run at the end since it makes osmo-hnbgw <= 1.3.0 crash: OS#5676 */
2767 execute(TC_hnb_reregister_reuse_sctp_assoc());
Neels Hofmeyrd019cc02023-06-02 16:31:23 +02002768
2769 /* Run at the end since it messes with the SCCP config */
2770 execute( TC_apply_sccp() );
Daniel Willmann19b8d902022-01-05 09:12:34 +01002771}
2772
2773}