blob: cd8ac7a07523a4b1b524fb61dc6041bf5849ddba [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;
Pau Espin Pedrol1158cc62024-03-21 17:21:35 +010059import from SDP_Templates all;
Daniel Willmann19b8d902022-01-05 09:12:34 +010060
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +020061import from PFCP_Types all;
62import from PFCP_Emulation all;
63import from PFCP_Templates all;
64import from PFCP_CodecPort all;
65
Neels Hofmeyr75d905b2023-04-27 00:30:25 +020066import from TCCConversion_Functions all;
Neels Hofmeyr7a48df12023-04-20 20:43:43 +020067import from MobileL3_Types all;
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +020068import from MobileL3_CommonIE_Types all;
69import from MobileL3_GMM_SM_Types all;
Neels Hofmeyr7a48df12023-04-20 20:43:43 +020070import from L3_Templates all;
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +020071import from L3_Common all;
Neels Hofmeyr7a48df12023-04-20 20:43:43 +020072
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +020073import from SCCPasp_Types all;
74
Neels Hofmeyr7a48df12023-04-20 20:43:43 +020075const integer NUM_MSC := 4;
76const integer NUM_SGSN := 4;
77
78const integer FIRST_MSC_IDX := 0;
79const integer FIRST_SGSN_IDX := NUM_MSC;
Neels Hofmeyr75d905b2023-04-27 00:30:25 +020080
Daniel Willmann19b8d902022-01-05 09:12:34 +010081modulepar {
82 /* IP address at which the HNodeB can be reached */
83 charstring mp_hnodeb_ip := "127.0.0.1";
84 integer mp_hnodeb_port := -1;
85
86 /* IP address at which the test binds */
87 charstring mp_hnbgw_ip := "127.0.0.1";
88 integer mp_hnbgw_iuh_port := 29169;
Neels Hofmeyrffcb8892023-06-27 01:09:57 +020089 integer mp_hnbgw_ctrl_port := 4262;
Daniel Willmann19b8d902022-01-05 09:12:34 +010090
91 charstring mp_mgw_ip := "127.0.0.1";
92 integer mp_mgw_port := 2427;
93
Neels Hofmeyr7a48df12023-04-20 20:43:43 +020094 RAN_Configurations mp_cn_cfg := {
95 /* MSCs (NUM_MSC entries) */
96 {
97 transport := RANAP_TRANSPORT_IuCS,
98 sccp_service_type := "mtp3_itu",
99 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
100 own_pc := 188, /* 0.23.4 first MSC emulation */
101 own_ssn := 142,
102 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
103 peer_ssn := 142,
104 sio := '83'O,
105 rctx := 1
106 },
107 {
108 transport := RANAP_TRANSPORT_IuCS,
109 sccp_service_type := "mtp3_itu",
110 sctp_addr := { 23907, "127.0.0.1", 2905, "127.0.0.1" },
111 own_pc := 2, /* 0.0.2 second MSC emulation */
112 own_ssn := 142,
113 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
114 peer_ssn := 142,
115 sio := '83'O,
116 rctx := 3
117 },
118 {
119 transport := RANAP_TRANSPORT_IuCS,
120 sccp_service_type := "mtp3_itu",
121 sctp_addr := { 23909, "127.0.0.1", 2905, "127.0.0.1" },
122 own_pc := 3, /* 0.0.3 third MSC emulation */
123 own_ssn := 142,
124 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
125 peer_ssn := 142,
126 sio := '83'O,
127 rctx := 5
128 },
129 {
130 transport := RANAP_TRANSPORT_IuCS,
131 sccp_service_type := "mtp3_itu",
132 sctp_addr := { 23911, "127.0.0.1", 2905, "127.0.0.1" },
133 own_pc := 4, /* 0.0.4 fourth MSC emulation */
134 own_ssn := 142,
135 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
136 peer_ssn := 142,
137 sio := '83'O,
138 rctx := 7
139 },
140
141 /* SGSNs (NUM_SGSN entries) */
142 {
143 transport := RANAP_TRANSPORT_IuCS,
144 sccp_service_type := "mtp3_itu",
145 sctp_addr := { /* local */ 23906, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
146 own_pc := 185, /* 0.23.1 first SGSN emulation */
147 own_ssn := 142,
148 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
149 peer_ssn := 142,
150 sio := '83'O,
151 rctx := 2
152 },
153 {
154 transport := RANAP_TRANSPORT_IuCS,
155 sccp_service_type := "mtp3_itu",
156 sctp_addr := { /* local */ 23908, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
157 own_pc := 10, /* 0.1.2 second SGSN emulation */
158 own_ssn := 142,
159 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
160 peer_ssn := 142,
161 sio := '83'O,
162 rctx := 4
163 },
164 {
165 transport := RANAP_TRANSPORT_IuCS,
166 sccp_service_type := "mtp3_itu",
167 sctp_addr := { /* local */ 23910, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
168 own_pc := 11, /* 0.1.3 third SGSN emulation */
169 own_ssn := 142,
170 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
171 peer_ssn := 142,
172 sio := '83'O,
173 rctx := 6
174 },
175 {
176 transport := RANAP_TRANSPORT_IuCS,
177 sccp_service_type := "mtp3_itu",
178 sctp_addr := { /* local */ 23912, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
179 own_pc := 12, /* 0.1.4 fourth SGSN emulation */
180 own_ssn := 142,
181 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
182 peer_ssn := 142,
183 sio := '83'O,
184 rctx := 8
185 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100186 };
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200187
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +0200188 boolean mp_enable_pfcp_tests := false;
189
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200190 /* IP address at which we listen for PFCP to emulate a UPF in ttcn3 */
191 charstring mp_pfcp_ip_local := "127.0.0.1";
192
193 /* IP address from which the SUT (osmo-hnbgw) sends PFCP requests, and to which the ttcn3 UPF emulation sends
194 * PFCP responses. */
195 charstring mp_pfcp_ip_remote := "127.0.0.2";
Pau Espin Pedrol6c87ad92023-07-18 11:24:25 +0200196
197 boolean mp_validate_talloc_asn1 := true;
Pau Espin Pedrolee4ce862023-11-02 12:23:25 +0100198
199 /* The X31 timer configured at osmo-hnbgw (seconds). This provided an idea on
200 * minimum time the test must wait to consider this timer triggered */
201 integer mp_hnbgw_timer_x31 := 5;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100202}
203
204function MSC_UnitdataCallback(RANAP_PDU ranap) runs on RAN_Emulation_CT return template RANAP_PDU {
205 // TODO: Actually implement unitdata handling
Neels Hofmeyrcf6dc492023-06-27 00:51:08 +0200206 return omit;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100207}
208
209const RanOps MSC_RanOps := {
210 ranap_create_cb := refers(RAN_Emulation.RanapExpectedCreateCallback),
211 ranap_unitdata_cb := refers(MSC_UnitdataCallback),
212 ps_domain := false,
213 decode_dtap := false,
214 role_ms := false,
215 protocol := RAN_PROTOCOL_RANAP,
216 transport := RANAP_TRANSPORT_IuCS,
217 use_osmux := false,
Eric Wild6e511ce2022-04-02 21:35:56 +0200218 bssap_reset_retries := 1,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100219 sccp_addr_local := omit,
220 sccp_addr_peer := omit
221}
222
Pau Espin Pedrol264679f2023-11-29 15:52:00 +0100223type record MgwResponse {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100224 integer resp,
225 HostName mgw_rtp_ip,
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +0100226 /* if set, used after first received MDCX: */
227 HostName mgw_rtp_ip_mdcx optional,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100228 PortNumber mgw_rtp_port,
229 MgcpConnectionId mgcp_connection_id
230}
231type record MgcpParameters {
232 integer got_crcx_count,
233 integer got_dlcx_count,
234 MgcpCallId mgcp_call_id optional,
235 MgcpEndpoint mgcp_ep,
Pau Espin Pedrol264679f2023-11-29 15:52:00 +0100236 MgwResponse mgw_conn_ran,
237 MgwResponse mgw_conn_cn,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100238 uint7_t rtp_payload_type,
239 charstring rtp_sdp_format,
240 HostName hnb_rtp_ip,
241 PortNumber hnb_rtp_port,
242 HostName cn_rtp_ip,
243 PortNumber cn_rtp_port,
244 boolean use_osmux,
245 integer got_osmux_count
246}
247
248template (value) MgcpParameters t_MgcpParams := {
249 got_crcx_count := 0,
250 got_dlcx_count := 0,
251 mgcp_call_id := omit,
252 mgcp_ep := "rtpbridge/1@mgw",
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +0100253 mgw_conn_ran := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100254 resp := 1,
255 mgw_rtp_ip := "127.1.2.1",
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +0100256 mgw_rtp_ip_mdcx := omit,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100257 mgw_rtp_port := 10000,
258 mgcp_connection_id := '11111'H
259 },
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +0100260 mgw_conn_cn := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100261 resp := 1,
262 mgw_rtp_ip := "127.1.2.2",
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +0100263 mgw_rtp_ip_mdcx := omit,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100264 mgw_rtp_port := 20000,
265 mgcp_connection_id := '22222'H
266 },
Philipp Maier6c5ba0752023-07-04 16:53:40 +0200267 rtp_payload_type := 112,
268 rtp_sdp_format := "VND.3GPP.IUFP",
Daniel Willmann19b8d902022-01-05 09:12:34 +0100269 hnb_rtp_ip := "127.1.1.1",
270 hnb_rtp_port := 10001,
271 cn_rtp_ip := "127.1.3.1",
272 cn_rtp_port := 20001,
273 use_osmux := false,
274 got_osmux_count := 0
275}
276
277type record TestHdlrParams {
278 integer hnb_idx,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200279 /* cn_idx indicates which CN link from g_cn[] to connect to the test component.
280 * See also f_cn_idx(). */
281 integer cn_idx,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100282 hexstring imsi,
283 boolean ps_domain,
284 MgcpParameters mgcp_pars optional,
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200285 HnbConfig hnb optional,
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200286 boolean expect_separate_sccp_cr,
287 integer tx_sccp_cr_data_len,
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +0200288 charstring pfcp_local_addr,
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +0200289 octetstring nas_pdu optional,
290 /* local and remote SCCP addresses, used in TC_mscpool_paging_* */
291 SCCP_PAR_Address sccp_addr_msc optional,
292 SCCP_PAR_Address sccp_addr_hnbgw optional
Daniel Willmann19b8d902022-01-05 09:12:34 +0100293}
294
295/* We extend:
296 * RUA_ConnHdlr (for the Iuh side, emulating the HNB)
297 * RAN_ConnHdlr (for the Iu side, emulating the MSC)
298 * MGCP_ConnHdlr (for the MGCP side, emulating the MGW)
299 */
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200300type component ConnHdlr extends RAN_ConnHdlr, MGCP_ConnHdlr, RUA_ConnHdlr, PFCP_ConnHdlr {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100301 var integer g_sccp_conn_id;
302 var TestHdlrParams g_pars;
303 timer g_Tguard;
Neels Hofmeyr72a8d622023-01-26 13:47:01 +0100304
305 port TELNETasp_PT HNBGWVTY;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100306}
307
308
309const MGCPOps MSC_MGCPOps := {
310 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
311 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
312}
313
314function f_create_ranap_exp(octetstring l3_enc) runs on ConnHdlr {
315 BSSAP_PROC.call(RAN_register:{l3_enc, self}) {
316 [] BSSAP_PROC.getreply(RAN_register:{?, ?}) {};
317 }
318}
319
320
Daniel Willmannc79679a2022-08-23 17:48:39 +0200321const integer NUM_HNB := 2;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100322
Daniel Willmann19b8d902022-01-05 09:12:34 +0100323type record HnbConfig {
324 LocationAreaIdentification lai,
325 integer sac
326}
327
328type component test_CT extends CTRL_Adapter_CT {
329 var boolean g_initialized := false;
330
331 /********************* Iu side */
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200332 var RAN_Adapter g_cn[NUM_MSC + NUM_SGSN];
Daniel Willmann19b8d902022-01-05 09:12:34 +0100333
334 /********************* Iuh side */
335 var HnbConfig g_hnb_cfg[NUM_HNB];
336 var Iuh_Emulation_CT vc_Iuh[NUM_HNB];
337 var RUA_Emulation_CT vc_RUA[NUM_HNB];
338 port HNBAP_PT HNBAP[NUM_HNB];
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200339 /* Number of HNBs to be used/started by the test */
340 var integer g_num_hnbs := NUM_HNB;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100341
342 var MGCP_Emulation_CT vc_MGCP;
343 port TELNETasp_PT HNBGWVTY;
344 /* global test case guard timer (actual timeout value is set in f_init()) */
345 timer T_guard := 30.0;
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +0200346
347 /* The cnlink type 'msc' or 'sgsn', to be used in CTRL commands to obtain counters */
348 var charstring g_ctr_cn_node_name;
349 /* Counter state */
350 var CounterNameValsList g_ctr_cn;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100351}
352
353/* global altstep for global guard timer; */
354altstep as_Tguard() runs on test_CT {
355 [] T_guard.timeout {
356 setverdict(fail, "Timeout of T_guard");
357 mtc.stop;
358 }
359}
360
Daniel Willmann19b8d902022-01-05 09:12:34 +0100361function f_init_vty(charstring id := "foo") runs on test_CT {
362 if (HNBGWVTY.checkstate("Mapped")) {
363 /* skip initialization if already executed once */
364 return;
365 }
366 map(self:HNBGWVTY, system:HNBGWVTY);
367 f_vty_set_prompts(HNBGWVTY);
368 f_vty_transceive(HNBGWVTY, "enable");
369}
370
371function f_init_mgcp(charstring id) runs on test_CT {
372 id := id & "-MGCP";
373 var MGCPOps ops := {
374 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
375 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
376 }
377 var MGCP_conn_parameters pars := {
378 callagent_ip := mp_hnbgw_ip,
379 callagent_udp_port := -1,
380 mgw_ip := mp_mgw_ip,
381 mgw_udp_port := mp_mgw_port,
382 multi_conn_mode := false
383 }
384
385 vc_MGCP := MGCP_Emulation_CT.create(id);
386 map(vc_MGCP:MGCP, system:MGCP_CODEC_PT);
387 vc_MGCP.start(MGCP_Emulation.main(ops, pars, id));
388}
389
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200390function f_init_pfcp(charstring id) runs on ConnHdlr {
391 id := id & "-PFCP";
392
393 var PFCP_Emulation_Cfg pfcp_cfg := {
394 pfcp_bind_ip := mp_pfcp_ip_local,
395 pfcp_bind_port := PFCP_PORT,
396 pfcp_remote_ip := mp_pfcp_ip_remote,
397 pfcp_remote_port := PFCP_PORT,
398 role := UPF
399 };
400
401 vc_PFCP := PFCP_Emulation_CT.create(id) alive;
402 connect(self:PFCP, vc_PFCP:CLIENT);
403 connect(self:PFCP_PROC, vc_PFCP:CLIENT_PROC);
404 vc_PFCP.start(PFCP_Emulation.main(pfcp_cfg));
405}
406
Daniel Willmann19b8d902022-01-05 09:12:34 +0100407function f_init_hnodeb(charstring id, integer hnb_idx, RuaOps rua_ops) runs on test_CT {
408 id := id & "-Iuh" & int2str(hnb_idx);
409
410 /* Iuh lower layer (RUA/HNBAP demux) */
411 var Iuh_conn_parameters iuh_pars;
412 iuh_pars.remote_ip := mp_hnbgw_ip;
413 iuh_pars.remote_sctp_port := mp_hnbgw_iuh_port;
414 iuh_pars.local_ip := mp_hnodeb_ip;
415 iuh_pars.local_sctp_port := mp_hnodeb_port + hnb_idx;
416 vc_Iuh[hnb_idx] := Iuh_Emulation_CT.create(id);
417 connect(self:HNBAP[hnb_idx], vc_Iuh[hnb_idx]:HNBAP);
418
419 vc_RUA[hnb_idx] := RUA_Emulation_CT.create(id & "-RUA");
420 connect(vc_RUA[hnb_idx]:RUA, vc_Iuh[hnb_idx]:RUA);
421
422 /* Start Iuh side components */
423 vc_Iuh[hnb_idx].start(Iuh_Emulation.main(iuh_pars, id));
424 vc_RUA[hnb_idx].start(RUA_Emulation.main(rua_ops, id & "-RUA"));
425}
426
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200427private type record of boolean BooleanList;
428
429private function f_vty_cnlink_allow_attach(TELNETasp_PT pt, boolean ps_domain, BooleanList allow_attach_list)
430{
431 var charstring config := f_vty_transceive_ret(pt, "show running-config");
432
433 var charstring msc_sgsn;
434 if (ps_domain) {
435 msc_sgsn := "sgsn";
436 } else {
437 msc_sgsn := "msc";
438 }
439
440 f_vty_enter_config(pt);
441 for (var integer cn_nr := 0; cn_nr < sizeof(allow_attach_list); cn_nr := cn_nr+1) {
442 if (f_strstr(config, "\n" & msc_sgsn & " " & int2str(cn_nr) & "\n") < 0) {
443 /* There is no 'msc N' for this cn_nr in the running config, so don't create an empty cn by
444 * stepping into that config node. */
445 log(msc_sgsn, cn_nr, " is not configured, skipping");
446 continue;
447 }
448 f_vty_transceive(pt, msc_sgsn & " " & int2str(cn_nr));
449
450 if (allow_attach_list[cn_nr]) {
451 /* strict := false: ignore if osmo-hnbgw does not support this config option (latest build) */
452 f_vty_transceive(pt, "allow-attach", strict := false);
453 } else {
454 f_vty_transceive(pt, "no allow-attach", strict := false);
455 }
456 f_vty_transceive(pt, "exit");
457 }
458 f_vty_transceive(pt, "exit");
459}
460
461/* Start RAN adapter for CN link N.
462 * e.g. link for 'msc 0' = (ps_domain := false, cn_nr := 0)
463 * link for 'sgsn 3' = (ps_domain := true, cn_nr := 3)
464 */
465private function f_cn_nr_init(boolean ps_domain, integer cn_nr) runs on test_CT {
466 var RanOps ranops := MSC_RanOps;
467 ranops.ps_domain := ps_domain;
468 var integer cn_idx := f_cn_idx(ps_domain, cn_nr);
469 var charstring msc_sgsn := "msc";
470 if (ps_domain) {
471 msc_sgsn := "sgsn";
472 }
473 f_ran_adapter_init(g_cn[cn_idx], mp_cn_cfg[cn_idx], "HNBGW_Test." & msc_sgsn & int2str(cn_nr), ranops);
474 f_ran_adapter_start(g_cn[cn_idx]);
475}
476
477private function f_cn_idx_disconnect(integer cn_idx) runs on test_CT {
478 f_ran_adapter_cleanup(g_cn[cn_idx]);
479}
480
Daniel Willmann19b8d902022-01-05 09:12:34 +0100481/* global initialization function */
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200482function f_init(charstring id := "HNBGW", float guard_timeout := 30.0, integer nr_msc := 1, integer nr_sgsn := 1,
483 boolean start_hnb := true) runs on test_CT {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100484
Daniel Willmann19b8d902022-01-05 09:12:34 +0100485 T_guard.start(guard_timeout);
486 activate(as_Tguard());
487
488 /* RUA/RANAP emulation on top of lower-layer Iuh */
489 var RuaOps rua_ops := {
490 create_cb := refers(IuhRanapCreateCallback),
491 unitdata_cb := refers(IuhRanapUnitdataCallback)
492 };
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200493 for (var integer i := 0; i < g_num_hnbs; i := i+1) {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200494 g_hnb_cfg[i] := {
495 lai := {
Neels Hofmeyr497216f2023-06-27 00:59:26 +0200496 mcc_mnc := '00F110'H,
Daniel Willmannc79679a2022-08-23 17:48:39 +0200497 lac := 2342 + i
498 },
499 sac := 55
500 };
Daniel Willmann19b8d902022-01-05 09:12:34 +0100501 f_init_hnodeb(testcasename(), i, rua_ops);
502 }
503
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200504 f_init_vty("VirtHNBGW");
Neels Hofmeyrffcb8892023-06-27 01:09:57 +0200505 f_ipa_ctrl_start_client(mp_hnbgw_ip, mp_hnbgw_ctrl_port);
506
Daniel Willmann19b8d902022-01-05 09:12:34 +0100507 /* MSC emulation */
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200508
509 /* Make sure each MSC's internal state is "DISCONNECTED" at first */
510 for (var integer i := 0; i < NUM_MSC; i := i + 1) {
511 f_vty_transceive(HNBGWVTY, "msc " & int2str(i) & " ranap reset", strict := false);
512 }
513
514 var BooleanList allow_attach := { false, false, false, false };
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200515 for (var integer i := 0; i < nr_msc; i := i + 1) {
516 var integer cn_idx := FIRST_MSC_IDX + i;
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200517 allow_attach[i] := true;
518 f_cn_nr_init(ps_domain := false, cn_nr := i);
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200519 }
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200520 /* start the test with exactly all enabled MSCs allowed to attach */
521 f_vty_cnlink_allow_attach(HNBGWVTY, false, allow_attach);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100522
523 /* SGSN emulation */
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200524
525 /* Make sure each SGSN's internal state is "DISCONNECTED" at first */
526 for (var integer i := 0; i < NUM_SGSN; i := i + 1) {
527 f_vty_transceive(HNBGWVTY, "sgsn " & int2str(i) & " ranap reset", strict := false);
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200528 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100529
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200530 allow_attach := { false, false, false, false };
531 for (var integer i := 0; i < nr_sgsn; i := i + 1) {
532 var integer cn_idx := FIRST_SGSN_IDX + i;
533 allow_attach[i] := true;
534 f_cn_nr_init(ps_domain := true, cn_nr := i);
535 }
536 f_vty_cnlink_allow_attach(HNBGWVTY, true, allow_attach);
537
Daniel Willmann19b8d902022-01-05 09:12:34 +0100538 f_init_mgcp(id);
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200539
540 if (start_hnb) {
541 f_start_hnbs();
542 }
Neels Hofmeyr467eb7e2023-08-10 03:38:07 +0200543
544 /* Sometimes, the RUA InitialUE-Message from a test happens too quickly, before the RANAP RESET from
545 * RAN_Emulation is through, after above f_cn_nr_init(). In the pcap it seems to be a matter of 50 ms. Give some
546 * grace. */
547 f_sleep(1.0);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100548}
549
550friend function f_shutdown_helper() runs on test_CT {
Pau Espin Pedrol6c87ad92023-07-18 11:24:25 +0200551 if (mp_validate_talloc_asn1) {
552 f_verify_talloc_bytes(HNBGWVTY, {"asn1_context"}, 1);
553 }
Neels Hofmeyr75d905b2023-04-27 00:30:25 +0200554
Daniel Willmann19b8d902022-01-05 09:12:34 +0100555 all component.stop;
556 setverdict(pass);
557 mtc.stop;
558}
559
560/* helper function to start all of the simulated hNodeBs */
561function f_start_hnbs() runs on test_CT {
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200562 for (var integer i:= 0; i < g_num_hnbs; i := i+1) {
Harald Welted71d5962024-03-27 19:17:19 +0100563 f_hnbap_hnb_register(i, i);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100564 }
565}
566
567/***********************************************************************
568 * code running in test_CT, preparing start of per-UE ConnHdlr
569 ***********************************************************************/
570
571/* inbound RUA connection establishment on Iuh side */
572function IuhRanapCreateCallback(ContextId context_id, RUA_IEs.CN_DomainIndicator domain, charstring id)
573runs on RUA_Emulation_CT return RUA_ConnHdlr {
574 log("CreateCallback");
575 return null;
576}
577
578/* inbound RUA connectionless data on Iuh side */
579function IuhRanapUnitdataCallback(RANAP_PDU ranap)
580runs on RUA_Emulation_CT return template RANAP_PDU {
581 log("UnitdataCallback");
582 return omit;
583}
584
585private function f_start_handler_create(TestHdlrParams pars) runs on test_CT return ConnHdlr {
586 var ConnHdlr vc_conn;
587 var charstring id := testcasename() & int2str(pars.hnb_idx);
588
589 vc_conn := ConnHdlr.create(id);
590
591 /* Iuh RUA part */
592 connect(vc_conn:RUA, vc_RUA[pars.hnb_idx]:CLIENT);
593
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200594 /* MSC or SGSN */
595 connect(vc_conn:BSSAP, g_cn[pars.cn_idx].vc_RAN:CLIENT);
596 connect(vc_conn:BSSAP_PROC, g_cn[pars.cn_idx].vc_RAN:PROC);
597
Daniel Willmann19b8d902022-01-05 09:12:34 +0100598 /* MGCP part */
599 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
600 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
601
602 return vc_conn;
603}
604
605private function f_start_handler_run(ConnHdlr vc_conn, void_fn fn, TestHdlrParams pars) runs on test_CT {
606 var charstring id := testcasename(); // & int2str(pars.ran_idx);
607 /* We cannot use vc_conn.start(f_init_handler(fn, id, pars)); as we cannot have
608 * a stand-alone 'derefers()' call, see https://www.eclipse.org/forums/index.php/t/1091364/ */
609 pars.hnb := g_hnb_cfg[pars.hnb_idx];
Daniel Willmann19b8d902022-01-05 09:12:34 +0100610 vc_conn.start(derefers(fn)(id, pars));
611}
612
613function f_start_handler_with_pars(void_fn fn, template (value) TestHdlrParams pars)
614runs on test_CT return ConnHdlr {
615 var ConnHdlr vc_conn;
616 vc_conn := f_start_handler_create(valueof(pars));
617 f_start_handler_run(vc_conn, fn, valueof(pars));
618 return vc_conn;
619}
620
621/***********************************************************************
622 * code running inside per-UE ConnHdlr
623 ***********************************************************************/
624
625type function void_fn(charstring id, TestHdlrParams pars) runs on ConnHdlr;
626
627function f_init_handler(TestHdlrParams pars, float t_guard := 20.0) runs on ConnHdlr {
628 /* make parameters available via component variable */
629 g_pars := pars;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200630
631 f_init_pfcp(testcasename());
632
Daniel Willmann19b8d902022-01-05 09:12:34 +0100633 /* start guard timer and activate it as default */
634 g_Tguard.start(t_guard);
635 activate(as_Tguard_ConnHdlr());
636
Neels Hofmeyr72a8d622023-01-26 13:47:01 +0100637 map(self:HNBGWVTY, system:HNBGWVTY);
638 f_vty_set_prompts(HNBGWVTY);
639 f_vty_transceive(HNBGWVTY, "enable");
640
Daniel Willmann19b8d902022-01-05 09:12:34 +0100641 /* TODO: CTRL? */
Neels Hofmeyr59517222023-06-23 04:46:59 +0200642
643 f_sleep(1.0);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100644}
645
646/* global altstep for global guard timer; */
647private altstep as_Tguard_ConnHdlr() runs on ConnHdlr {
648 [] g_Tguard.timeout {
649 setverdict(fail, "Timeout of T_guard");
650 mtc.stop;
651 }
652}
653
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100654private function f_bssap_expect(template (present) RANAP_PDU exp_rx) runs on ConnHdlr return RANAP_PDU
655{
656 var RANAP_PDU rx;
657 timer T := 5.0;
658 T.start;
659 alt {
660 [] BSSAP.receive(exp_rx) -> value rx {
661 setverdict(pass);
662 }
663 [] BSSAP.receive(RANAP_PDU:?) {
664 setverdict(fail, "Got an unexpected RANAP message on BSSAP port, was waiting for ", exp_rx);
665 mtc.stop;
666 }
667 [] T.timeout {
668 setverdict(fail, "Timeout waiting for RANAP on BSSAP port: ", exp_rx);
669 mtc.stop;
670 }
671 }
672 T.stop;
673 return rx;
674}
675
Daniel Willmann19b8d902022-01-05 09:12:34 +0100676/* send RANAP on Iuh and expect it to show up on Iu */
677function f_iuh2iu(template (present) RANAP_PDU tx, template RANAP_PDU exp_rx := omit)
678runs on ConnHdlr return RANAP_PDU {
679 var RANAP_PDU rx;
680 timer T := 5.0;
681
682 if (istemplatekind(exp_rx, "omit")) {
683 exp_rx := tx;
684 }
685
686 RUA.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100687
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100688 return f_bssap_expect(exp_rx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100689}
690
691/* send RANAP on Iu and expect it to show up on Iuh */
692function f_iu2iuh(template (present) RANAP_PDU tx, template RANAP_PDU exp_rx := omit)
693runs on ConnHdlr return RANAP_PDU {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100694 if (istemplatekind(exp_rx, "omit")) {
695 exp_rx := tx;
696 }
697
698 BSSAP.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100699
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100700 return f_rua_expect(exp_rx)
701}
702
703/* expect to receive a specific RUA message on Iuh */
704private function f_rua_expect(template (present) RANAP_PDU exp_rx) runs on ConnHdlr return RANAP_PDU
705{
706 var RANAP_PDU rx;
707 timer T := 5.0;
708 T.start;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100709 alt {
710 [] RUA.receive(exp_rx) -> value rx {
711 setverdict(pass);
712 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100713 [] RUA.receive(RANAP_PDU:?) {
714 setverdict(fail, "Got an unexpected RUA message, was waiting for ", exp_rx);
715 mtc.stop;
716 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100717 [] T.timeout {
718 setverdict(fail, "Timeout waiting for Iuh ", exp_rx);
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100719 mtc.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100720 }
721 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100722 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100723 return rx;
724}
725
726/* send RANAP on Iuh and expect it to show up on Iu */
727function f_iuh2iu_connect(template (present) RANAP_PDU tx, template RANAP_PDU exp_rx := omit)
728runs on ConnHdlr return RANAP_PDU {
729 var RANAP_PDU rx;
730 timer T := 5.0;
731
732 if (istemplatekind(exp_rx, "omit")) {
733 exp_rx := tx;
734 }
735
736 /* create an expect on the Iu side for the random NAS portion */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200737 if (g_pars.expect_separate_sccp_cr) {
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200738 f_ran_register_sccp_cr_without_payload();
739 } else {
740 var template (omit) octetstring nas := f_ranap_extract_l3(valueof(tx));
741 f_ran_register_exp(valueof(nas));
742 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100743
744 /* send it via Iuh (creating a RUA connection) */
745 RUA.send(RUA_Conn_Req:{g_pars.ps_domain, tx});
746
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200747 if (g_pars.expect_separate_sccp_cr) {
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200748 /* Acknowledge the empty SCCP CR. RAN_Emulation does the confirmation, no need to respond. */
749 BSSAP.receive(tr_RANAP_Conn_Req());
750 }
751
Daniel Willmann19b8d902022-01-05 09:12:34 +0100752 /* expect to receive it on the Iu side */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100753 return f_bssap_expect(exp_rx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100754}
755
Neels Hofmeyr99b7d402023-02-20 14:26:31 +0100756/* 3GPP TS 48.006 9.2 Connection release:
757 *
758 * The MSC sends a SCCP released message. This message shall not contain
759 * any user data field.
760 *
761 * So what we expect normally is:
762 *
763 * HNBGW MSC
764 * RUA --id-Disconnect-------> | ---Data-Form-1(!)---> | Iu-ReleaseComplete
765 * | <--Released---------- | (no data)
766 *
767 * This function tests osmo-hnbgw behavior if the CN fails to send a RLSD:
768 * after some timeout, osmo-hnbgw should send a RLSD to the CN.
769 */
Daniel Willmann19b8d902022-01-05 09:12:34 +0100770function f_iuh2iu_disconnect(template (present) RANAP_PDU tx, RUA_IEs.Cause cause,
771 template RANAP_PDU exp_rx := omit)
772runs on ConnHdlr return RANAP_PDU {
773 var RANAP_PDU rx
Pau Espin Pedrolee4ce862023-11-02 12:23:25 +0100774 timer T := int2float(mp_hnbgw_timer_x31) + 1.0;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100775
776 if (istemplatekind(exp_rx, "omit")) {
777 exp_rx := tx;
778 }
779
780 /* send it via Iuh (creating a RUA connection) */
781 RUA.send(RUA_Disc_Req:{tx, cause});
782
783 /* expect to receive it on the Iu side */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100784 rx := f_bssap_expect(exp_rx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100785
786 /* expect disconnect on the Iu side */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100787 T.start;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100788 alt {
789 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
790 setverdict(pass);
791 }
792 [] T.timeout {
793 setverdict(fail, "Timeout waiting for Iu disconnect");
794 return rx;
795 }
796
797 }
798 return rx;
799}
800
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200801private function f_build_initial_ue_with_nas(TestHdlrParams pars, octetstring nas)
802 return RANAP_PDU {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100803 var LAI lai := {
804 pLMNidentity := hex2oct(pars.hnb.lai.mcc_mnc),
805 lAC := int2oct(pars.hnb.lai.lac, 2),
806 iE_Extensions := omit
807 };
808 var SAI sai := {
809 pLMNidentity := lai.pLMNidentity,
810 lAC := lai.lAC,
811 sAC := int2oct(pars.hnb.sac, 2),
812 iE_Extensions := omit
813 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100814 var IuSignallingConnectionIdentifier sigc_id := int2bit(f_rnd_int(1000), 24);
815 var GlobalRNC_ID grnc_id := {
816 pLMNidentity := lai.pLMNidentity,
817 rNC_ID := 2342
818 }
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200819 var template RANAP_PDU ret;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100820 if (pars.ps_domain) {
821 var RAC rac := '00'O;
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200822 ret := ts_RANAP_initialUE_PS(lai, rac, sai, nas, sigc_id, grnc_id);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100823 } else {
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200824 ret := ts_RANAP_initialUE_CS(lai, sai, nas, sigc_id, grnc_id);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100825 }
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200826 return valueof(ret);
827}
828
829/* build a RANAP InitialUE based on the TestHdlrParams */
830friend function f_build_initial_ue(TestHdlrParams pars) return RANAP_PDU {
831
832 var octetstring nas;
833
834 if (pars.tx_sccp_cr_data_len == 0) {
835 nas := f_rnd_octstring(10);
836 } else {
837 /* The test asks for an exact number of Optional Data bytes. */
838
839 /* First see what size the RANAP part of the payload data is,
840 * to adjust the NAS PDU size to the size requested by the test (pars.tx_sccp_cr_data_len). */
841 var RANAP_PDU initial_ue := f_build_initial_ue_with_nas(pars, '00'O);
842
843 var octetstring ranap_plus_one_byte_nas := enc_RANAP_PDU(initial_ue);
844 var integer ranap_length := lengthof(ranap_plus_one_byte_nas) - 1;
845
846 log("ranap_plus_one_byte_nas = ", lengthof(ranap_plus_one_byte_nas), " bytes, ", initial_ue, " = ",
847 ranap_plus_one_byte_nas);
848 log("ranap_length = ", ranap_length);
849
850 /* SCCP CR has a payload length limit of 130 bytes. To trigger this limit, the RANAP + NAS PDU has to be
851 * > 130 bytes. It doesn't need to be 131 bytes in the NAS PDU alone, but let's just make it definitely
852 * large enough. To test for this limit, pars.tx_sccp_cr_data_len asks for a specific amount of data len. */
853 nas := f_rnd_octstring(pars.tx_sccp_cr_data_len - ranap_length);
854 }
855
856 var RANAP_PDU ret := f_build_initial_ue_with_nas(pars, nas);
857
858 if (pars.tx_sccp_cr_data_len != 0) {
859 for (var integer attempts := 0; attempts < 2; attempts := attempts + 1) {
860 var octetstring check_len := enc_RANAP_PDU(ret);
861 log("final RANAP PDU length = ", lengthof(check_len));
862 if (lengthof(check_len) == pars.tx_sccp_cr_data_len) {
863 return ret;
864 }
865 nas := f_rnd_octstring(lengthof(nas) + (pars.tx_sccp_cr_data_len - lengthof(check_len)));
866 log("that was off, changed NAS length to ", lengthof(nas), " and trying again");
867 ret := f_build_initial_ue_with_nas(pars, nas);
868 }
869 setverdict(fail, "Ended up with wrong Optional Data length");
870 mtc.stop;
871 }
872 return ret;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100873}
874
875/* build a RANAP RAB AssignmentResponse based on the TestHdlrParams */
876friend function f_build_rab_ass_resp(TestHdlrParams pars) return RANAP_PDU {
877 var template RAB_SetupOrModifiedList rab_sml;
878
879 rab_sml := ts_RAB_SMdL(t_RAB_id(23), f_ts_RAB_TLA("192.168.1.23"), t_RAB_binding_port(1234));
880
881 return valueof(ts_RANAP_RabAssResp(rab_sml));
882}
883
884
885/***********************************************************************
886 * HNBAP Testing
887 ***********************************************************************/
888
889
Harald Welted71d5962024-03-27 19:17:19 +0100890function f_hnbap_hnb_register(integer hnb_idx := 0, integer cell_id := 0, boolean expect_reject := false) runs on test_CT
Daniel Willmann19b8d902022-01-05 09:12:34 +0100891{
892 timer T := 2.0;
893
Neels Hofmeyrfffe79b2023-06-27 01:16:15 +0200894 HNBAP[hnb_idx].send(ts_HNBAP_HNBRegisterRequest(char2oct("TTCN3-HNB-" & int2str(hnb_idx)),
Daniel Willmann19b8d902022-01-05 09:12:34 +0100895 '00F110'O,
Daniel Willmannc79679a2022-08-23 17:48:39 +0200896 int2bit(1 + cell_id, 28),
Daniel Willmann19b8d902022-01-05 09:12:34 +0100897 int2oct(2, 2),
898 int2oct(3, 1),
899 int2oct(4, 2)));
900
901 T.start;
902 alt {
903 [] HNBAP[hnb_idx].receive(tr_HNBAP_HNBRegisterAccept(?)) {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200904 if (expect_reject) {
905 setverdict(fail, "Rx HNB Register Accept while expecting reject");
906 } else {
907 setverdict(pass);
908 }
909 }
910 [] HNBAP[hnb_idx].receive(tr_HNBAP_HNBRegisterReject(?)) {
911 if (expect_reject) {
912 setverdict(pass);
913 } else {
914 setverdict(fail, "Rx HNB Register Reject while expecting accept");
915 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100916 }
917 [] HNBAP[hnb_idx].receive(IUHEM_Event:?) {
918 repeat;
919 }
920 [] T.timeout {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200921 setverdict(fail, "Timeout waiting for HNB Register response");
Daniel Willmann19b8d902022-01-05 09:12:34 +0100922 }
923 }
924}
925
926testcase TC_hnb_register() runs on test_CT {
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200927 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200928 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +0100929 f_hnbap_hnb_register(0);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100930 f_shutdown_helper();
931}
932
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200933/* Try to register the same HNB from 2 different concurrent connections. Second
934 * one should be rejected. */
Daniel Willmannc79679a2022-08-23 17:48:39 +0200935testcase TC_hnb_register_duplicate() runs on test_CT {
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200936 g_num_hnbs := 2;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200937 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +0100938 f_hnbap_hnb_register(0);
939 f_hnbap_hnb_register(1, 0, expect_reject := true);
Daniel Willmannc79679a2022-08-23 17:48:39 +0200940 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
941 f_shutdown_helper();
942}
943
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200944/* Try to register the same HNB in the same connection already established, aka
945 * duplicate HNB Register Request. It should be accepted and new configuration
946 * applied. TS 25.469 8.2.4 */
947testcase TC_hnb_register_duplicate_reuse_sctp_assoc() runs on test_CT {
948 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200949 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +0100950 f_hnbap_hnb_register(0);
951 f_hnbap_hnb_register(0);
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200952 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
953 f_shutdown_helper();
954}
955
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +0200956/* Drop HNBAP conn (HNBAP DEREG) and reconnect it (HNBAP REG) using same SCTP association.
957 * Related: OS#5676, SYS#6113 */
958testcase TC_hnb_reregister_reuse_sctp_assoc() runs on test_CT {
959 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200960 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +0100961 f_hnbap_hnb_register(0);
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +0200962 HNBAP[0].send(ts_HNBAP_HNBDe_Register(ts_HnbapCause(unspecified)));
Harald Welted71d5962024-03-27 19:17:19 +0100963 f_hnbap_hnb_register(0);
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +0200964 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
965 f_shutdown_helper();
966}
967
Daniel Willmann19b8d902022-01-05 09:12:34 +0100968/***********************************************************************
969 * RUA / RANAP Testing
970 ***********************************************************************/
971
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200972/* Translate from {msc,sgsn}x{0..n} to the proper index to use in g_cn[].
973 * g_cn[] stores CN links, MSCs and SGSNs in the same array.
974 * For example, for 'sgsn 23', use g_cn[ f_cn_idx(ps_domain := true, cn_nr := 23) ].
975 *
976 * Note the naming:
977 * cn_nr is the number used in the cfg file, as in 'msc 0'.
978 * cn_idx is the array index in g_cn[].
979 */
980private function f_cn_idx(boolean ps_domain, integer cn_nr := 0) return integer
981{
982 if (ps_domain) {
983 return FIRST_SGSN_IDX + cn_nr;
984 }
985 return FIRST_MSC_IDX + cn_nr;
986}
987
Daniel Willmann19b8d902022-01-05 09:12:34 +0100988private template (value) TestHdlrParams
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200989t_pars(integer imsi_suffix, boolean ps_domain := false, integer hnb_idx := 0,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200990 boolean expect_separate_sccp_cr := false, integer tx_sccp_cr_data_len := 0,
991 integer cn_nr := 0) := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100992 hnb_idx := hnb_idx,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200993 cn_idx := f_cn_idx(ps_domain, cn_nr),
Daniel Willmann19b8d902022-01-05 09:12:34 +0100994 imsi := f_gen_imsi(imsi_suffix),
995 ps_domain := ps_domain,
Pau Espin Pedrolaf746502023-11-29 16:18:28 +0100996 mgcp_pars := t_MgcpParams,
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200997 hnb := omit, /* filled in later */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200998 expect_separate_sccp_cr := expect_separate_sccp_cr,
999 tx_sccp_cr_data_len := tx_sccp_cr_data_len,
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02001000 pfcp_local_addr := mp_pfcp_ip_local,
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02001001 nas_pdu := omit,
1002 sccp_addr_msc := omit,
1003 sccp_addr_hnbgw := omit
Daniel Willmann19b8d902022-01-05 09:12:34 +01001004}
1005
1006/* Create an Iuh connection; send InitialUE; expect it to appear on new SCCP conenction */
1007friend function f_tc_initial_ue(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1008 f_init_handler(pars);
1009 var RANAP_PDU tx := f_build_initial_ue(g_pars);
1010 f_iuh2iu_connect(tx);
1011}
1012testcase TC_ranap_cs_initial_ue() runs on test_CT {
1013 var ConnHdlr vc_conn;
1014
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001015 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001016 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001017
1018 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue), t_pars(1));
1019 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001020
1021 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001022}
1023testcase TC_ranap_ps_initial_ue() runs on test_CT {
1024 var ConnHdlr vc_conn;
1025
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001026 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001027 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001028
1029 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue), t_pars(2, true));
1030 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001031
1032 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001033}
1034
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001035private function f_vty_set_sccp_max_optional_data(TELNETasp_PT pt, integer val := -1)
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001036{
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001037 var charstring valstr;
1038 if (val < 0) {
1039 valstr := "standard";
1040 } else {
1041 valstr := int2str(val);
1042 }
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001043 f_vty_enter_config(pt);
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001044 f_vty_transceive(pt, "cs7 instance 0");
1045 f_vty_transceive(pt, "sccp max-optional-data " & valstr);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001046 f_vty_transceive(pt, "end");
1047}
1048
1049testcase TC_ranap_cs_initial_ue_empty_cr() runs on test_CT {
1050 var ConnHdlr vc_conn;
1051
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001052 g_num_hnbs := 1;
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001053 f_init();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001054
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001055 f_vty_set_sccp_max_optional_data(HNBGWVTY, 0);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001056
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001057 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 +02001058 vc_conn.done;
1059
1060 /* reset */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001061 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001062
1063 f_shutdown_helper();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001064}
1065testcase TC_ranap_ps_initial_ue_empty_cr() runs on test_CT {
1066 var ConnHdlr vc_conn;
1067
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001068 g_num_hnbs := 1;
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001069 f_init();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001070
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001071 f_vty_set_sccp_max_optional_data(HNBGWVTY, 0);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001072
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001073 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 +02001074 vc_conn.done;
1075
1076 /* reset */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001077 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001078
1079 f_shutdown_helper();
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001080}
1081
1082type record Testdata_CR_Limit {
1083 integer data_len,
1084 integer max_optional_data,
1085 boolean expect_separate_sccp_cr
1086};
1087type record of Testdata_CR_Limit Testdata_CR_Limits;
1088
1089testcase TC_sccp_cr_limit() runs on test_CT {
1090 g_num_hnbs := 1;
1091 f_init();
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001092
1093 const Testdata_CR_Limits tests := {
1094 { data_len := 130, max_optional_data := -1, expect_separate_sccp_cr := false },
1095 { data_len := 131, max_optional_data := -1, expect_separate_sccp_cr := true },
1096
1097 { data_len := 100, max_optional_data := 100, expect_separate_sccp_cr := false },
1098 { data_len := 101, max_optional_data := 100, expect_separate_sccp_cr := true },
1099
1100 { data_len := 200, max_optional_data := 200, expect_separate_sccp_cr := false },
1101 { data_len := 201, max_optional_data := 200, expect_separate_sccp_cr := true }
1102 };
1103
1104 var integer csps;
1105 for (csps := 0; csps < 2; csps := csps + 1) {
1106 var boolean ps_domain := (csps > 0);
1107
1108 var integer i;
1109 for (i := 0; i < lengthof(tests); i := i + 1) {
1110 var Testdata_CR_Limit t := tests[i];
1111 f_logp(HNBGWVTY,
1112 "TEST PART TC_sccp_cr_limit ps_domain=" & f_bool2str(ps_domain)
1113 & " data_len=" & int2str(t.data_len)
1114 & " max_optional_data=" & int2str(t.max_optional_data)
1115 & " expect_separate_sccp_cr=" & f_bool2str(t.expect_separate_sccp_cr)
1116 );
1117
1118 f_vty_set_sccp_max_optional_data(HNBGWVTY, t.max_optional_data);
1119 var ConnHdlr vc_conn;
1120 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue),
1121 t_pars(100 + i,
1122 ps_domain := ps_domain,
1123 expect_separate_sccp_cr := t.expect_separate_sccp_cr,
1124 tx_sccp_cr_data_len := t.data_len));
1125 vc_conn.done;
1126 }
1127 }
1128
1129 /* reset */
1130 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001131
1132 f_shutdown_helper();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001133}
1134
Daniel Willmann19b8d902022-01-05 09:12:34 +01001135/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1136 * Return true when an OK reply was sent, false otherwise.
1137 * Count occurrence of Osmux, include Osmux parameters in the reply if necessary. */
1138function f_handle_crcx(inout MgcpParameters pars, MgcpCommand mgcp_cmd) return template MgcpResponse {
Pau Espin Pedrol264679f2023-11-29 15:52:00 +01001139 var MgwResponse conn := pars.mgw_conn_ran;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001140 if (pars.got_crcx_count > 0) {
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001141 conn := pars.mgw_conn_cn;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001142 }
1143 pars.got_crcx_count := pars.got_crcx_count + 1;
1144
1145 var MgcpMessage mgcp_msg := {
1146 command := mgcp_cmd
1147 }
1148 var template MgcpResponse mgcp_resp;
1149 var MgcpOsmuxCID osmux_cid;
1150 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1151 if (ispresent(pars.mgcp_call_id)) {
1152 if (pars.mgcp_call_id != call_id) {
1153 setverdict(fail, "CRCX contained unexpected call id. Expected:", pars.mgcp_call_id, " got:", call_id);
1154 mtc.stop;
1155 }
1156 } else {
1157 pars.mgcp_call_id := call_id;
1158 }
1159
1160 /* When the endpoint contains a wildcard we keep the endpoint
1161 * identifier we have set up in pars. Otherwise we use the
1162 * endpoint name that the call agent has supplied */
1163 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1164 pars.mgcp_ep := mgcp_cmd.line.ep;
1165 }
1166
1167 if (conn.resp == -1) {
1168 /* Reply with rror */
1169 var MgcpResponse mgcp_rsp := {
1170 line := {
1171 code := "542",
1172 trans_id := mgcp_cmd.line.trans_id,
1173 string := "FORCED_FAIL"
1174 },
1175 sdp := omit
1176
1177 }
1178 var MgcpParameter mgcp_rsp_param := {
1179 code := "Z",
1180 val := pars.mgcp_ep
1181 };
1182 mgcp_rsp.params[0] := mgcp_rsp_param;
1183 return mgcp_rsp;
1184 }
1185
1186 if (conn.resp == 0) {
1187 /* Do not reply at all */
1188 return omit;
1189 }
1190
1191 if (conn.resp != 1) {
1192 setverdict(fail, "Unexpected value for pars.mgw_conn_*.resp, expect -1, 0 or 1");
1193 mtc.stop;
1194 }
1195
1196 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1197 hex2str(pars.mgcp_call_id), "42",
1198 conn.mgw_rtp_port,
1199 { int2str(pars.rtp_payload_type) },
1200 { valueof(ts_SDP_rtpmap(pars.rtp_payload_type,
1201 pars.rtp_sdp_format)),
1202 valueof(ts_SDP_ptime(20)) }));
1203
1204 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1205 if (not pars.use_osmux) {
1206 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1207 mtc.stop;
1208 }
1209 pars.got_osmux_count := pars.got_osmux_count + 1;
1210 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1211 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1212 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1213 if (osmux_cid != -1) {
1214 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1215 mtc.stop;
1216 }
1217
1218 osmux_cid := 0;
1219 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1220 } else {
1221 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1222 }
1223
1224 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(pars.mgcp_ep));
1225
1226 return mgcp_resp;
1227}
1228
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001229friend function f_create_rab(inout MgcpParameters pars) runs on ConnHdlr {
1230 f_rab_ass_req(pars);
1231 f_rab_ass_resp(pars);
1232}
1233
1234friend function f_rab_ass_req(inout MgcpParameters pars) runs on ConnHdlr {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001235 var MgcpCommand mgcp_cmd;
1236 var RANAP_PDU tx;
1237 var template RAB_SetupOrModifyList rab_sml;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001238 timer T := 5.0;
1239
1240 /* Send RAB Assignment Request */
1241 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));
1242 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1243 BSSAP.send(tx);
1244 T.start;
1245
1246 /* Handle MGCP CRCX */
1247 alt {
1248 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1249 log("CRCX1", mgcp_cmd);
1250 var template MgcpResponse mgcp_rsp := f_handle_crcx(pars, mgcp_cmd);
1251 MGCP.send(valueof(mgcp_rsp));
1252 }
1253 [] T.timeout {
1254 setverdict(fail, "Timeout waiting for MGCP");
1255 }
1256 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001257 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001258
1259 /* Expect RAB Assignment Request with IP/port from CRCX ACK via Iuh */
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001260 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 +01001261 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1262
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001263 f_rua_expect(tx);
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001264}
1265
1266friend function f_rab_ass_resp(inout MgcpParameters pars) runs on ConnHdlr {
1267 var MgcpCommand mgcp_cmd;
1268 var RANAP_PDU tx;
1269 var template RAB_SetupOrModifiedList rab_smdl;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001270
1271 /* Send back RAB Assignment Response via Iuh */
1272 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));
1273 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1274 RUA.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001275
1276 interleave {
1277 /* Expect MDCX with IP/port from RAB Assignment Response */
1278 [] 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 +01001279 var HostName mgw_rtp_ip;
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001280 var boolean exp_rua_rab_reass := false;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001281 log("MDCX1", mgcp_cmd);
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001282 if (ispresent(pars.mgw_conn_ran.mgw_rtp_ip_mdcx)) {
1283 mgw_rtp_ip := pars.mgw_conn_ran.mgw_rtp_ip_mdcx;
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001284 if (pars.mgw_conn_ran.mgw_rtp_ip != pars.mgw_conn_ran.mgw_rtp_ip_mdcx) {
1285 exp_rua_rab_reass := true;
1286 }
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001287 } else {
1288 mgw_rtp_ip := pars.mgw_conn_ran.mgw_rtp_ip;
1289 }
1290
Daniel Willmann19b8d902022-01-05 09:12:34 +01001291 /* Verify SDP of MDCX */
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001292 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 +01001293 { 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 +01001294 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 +01001295 MGCP.send(valueof(mgcp_rsp));
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001296
1297 /* If IP address changed, we expect HNBGW to Modify the RAB through RAB-Ass-Req: */
1298 if (exp_rua_rab_reass) {
1299 var template RAB_SetupOrModifyList rab_sml;
1300 /* Expect RAB Assignment Request with IP/port from MDCX ACK via Iuh */
1301 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));
1302 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1303
1304 f_rua_expect(tx);
1305 /* Send back RAB Assignment Response via Iuh */
1306 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));
1307 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1308 RUA.send(tx);
1309 /* This shouldn't trigger any MGCP, since nothing changed on the HNB IP side. Continue below. */
1310 }
Daniel Willmann19b8d902022-01-05 09:12:34 +01001311 }
1312 /* Handle CRCX for second leg of endpoint, answer with IP/port */
1313 [] MGCP.receive(tr_CRCX(pars.mgcp_ep, tr_SDP(pars.cn_rtp_ip, pars.cn_rtp_port))) -> value mgcp_cmd {
1314 log("CRCX2", mgcp_cmd);
1315 /* Verify SDP of CRCX */
1316 var template MgcpResponse mgcp_rsp := f_handle_crcx(pars, mgcp_cmd);
1317 MGCP.send(valueof(mgcp_rsp));
1318 }
1319 }
1320
1321 /* Expect RAB Assignment Response with IP/port from second CRCX ACK */
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001322 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 +01001323 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1324
Neels Hofmeyrdc416c92023-03-09 02:47:50 +01001325 f_bssap_expect(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001326}
1327
1328private altstep as_mgcp_dlcx(inout TestHdlrParams pars) runs on ConnHdlr {
1329 var MgcpCommand mgcp_cmd;
1330
1331 [] MGCP.receive(tr_DLCX(pars.mgcp_pars.mgcp_ep)) -> value mgcp_cmd {
1332 log("DLCX", mgcp_cmd);
1333 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1334 pars.mgcp_pars.got_dlcx_count := pars.mgcp_pars.got_dlcx_count + 1;
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001335 if (pars.mgcp_pars.got_dlcx_count != pars.mgcp_pars.got_crcx_count) {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001336 repeat;
1337 }
1338 setverdict(pass);
1339 }
1340}
1341
1342friend function f_tc_rab_assignment(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1343 var MgcpCommand mgcp_cmd;
1344 var RANAP_PDU tx;
1345 timer T := 5.0;
1346
1347 f_init_handler(pars);
1348 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1349
1350 tx := f_build_initial_ue(g_pars);
1351 f_iuh2iu_connect(tx);
1352
1353 f_create_rab(pars.mgcp_pars);
1354
1355 /* Send Iu Release */
1356 tx := valueof(ts_RANAP_IuReleaseCommand(ts_RanapCause_om_intervention));
1357 f_iu2iuh(tx);
1358
1359 T.start;
1360 alt {
1361 [] as_mgcp_dlcx(pars) {}
1362 [] T.timeout {
1363 setverdict(fail, "Timeout waiting for DLCX");
1364 }
1365 }
1366
1367 tx := valueof(ts_RANAP_IuReleaseComplete());
1368 f_iuh2iu(tx);
1369}
1370
1371testcase TC_rab_assignment() runs on test_CT {
1372 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001373 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001374 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001375
1376 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assignment), t_pars(3));
1377 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001378
1379 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001380}
1381
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001382friend function f_tc_rab_assign_fail(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1383 var MgcpCommand mgcp_cmd;
1384 var RANAP_PDU tx;
1385 timer T := 5.0;
1386
1387 f_init_handler(pars);
1388 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1389
1390 tx := f_build_initial_ue(g_pars);
1391 f_iuh2iu_connect(tx);
1392
1393 f_rab_ass_req(pars.mgcp_pars);
1394
1395 /* Send RAB failed list in response */
1396 tx := valueof(ts_RANAP_RabAssResp(rab_fl := ts_RAB_FL(t_RAB_id(23), ts_RanapCause_om_intervention)));
1397 f_iuh2iu(tx);
1398
1399 T.start;
1400 alt {
1401 [] as_mgcp_dlcx(pars) {}
1402 [] T.timeout {
1403 setverdict(fail, "Timeout waiting for DLCX");
1404 }
1405 }
1406}
1407
1408testcase TC_rab_assign_fail() runs on test_CT {
1409 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001410 g_num_hnbs := 1;
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001411 f_init();
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001412
1413 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assign_fail), t_pars(4));
1414 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001415
1416 f_shutdown_helper();
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001417}
1418
Daniel Willmann19b8d902022-01-05 09:12:34 +01001419friend function f_tc_rab_release(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1420 var MgcpCommand mgcp_cmd;
1421 var RANAP_PDU tx;
1422 timer T := 15.0;
1423
1424 f_init_handler(pars);
1425 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1426
1427 tx := f_build_initial_ue(g_pars);
1428 f_iuh2iu_connect(tx);
1429
1430 f_create_rab(pars.mgcp_pars);
1431
1432 /* Send RAB Release */
Daniel Willmann9e789be2022-02-22 13:30:51 +01001433 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 +01001434 BSSAP.send(tx);
1435
1436 T.start;
1437
1438 alt {
1439 [] as_mgcp_dlcx(pars) {}
1440 [] T.timeout {
1441 setverdict(fail, "Timeout waiting for DLCX");
1442 }
1443 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001444 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001445
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001446 f_rua_expect(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001447}
1448
1449testcase TC_rab_release() runs on test_CT {
1450 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001451 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001452 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001453
1454 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_release), t_pars(5));
1455 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001456
1457 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001458}
1459
Daniel Willmann37c877f2022-02-22 16:47:06 +01001460friend function f_tc_rab_assign_mgcp_to(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1461 var MgcpCommand mgcp_cmd;
1462 var RANAP_PDU tx;
1463 var template RAB_SetupOrModifyList rab_sml;
1464 timer T := 15.0;
1465
1466 T.start;
1467 f_init_handler(pars);
1468 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1469
1470 tx := f_build_initial_ue(g_pars);
1471 f_iuh2iu_connect(tx);
1472
1473
1474 /* Send RAB Assignment Request */
1475 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));
1476 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1477 BSSAP.send(tx);
1478
1479 /* Ignore MGCP CRCX */
1480 alt {
1481 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1482 log("Ignoreing CRCX1", mgcp_cmd);
1483 repeat;
1484 }
1485 [] BSSAP.receive(tr_RANAP_IuReleaseRequest(?)) { }
1486 [] T.timeout {
1487 setverdict(fail, "Timeout waiting for IuRelease");
1488 }
1489 }
1490
1491 /* Send Iu Release */
1492 tx := valueof(ts_RANAP_IuReleaseCommand(ts_RanapCause_om_intervention));
1493 f_iu2iuh(tx);
1494
1495 tx := valueof(ts_RANAP_IuReleaseComplete());
1496 f_iuh2iu(tx);
1497}
1498
1499testcase TC_rab_assign_mgcp_to() runs on test_CT {
1500 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001501 g_num_hnbs := 1;
Daniel Willmann37c877f2022-02-22 16:47:06 +01001502 f_init();
Daniel Willmann37c877f2022-02-22 16:47:06 +01001503
1504 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assign_mgcp_to), t_pars(6));
1505 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001506
1507 f_shutdown_helper();
Daniel Willmann37c877f2022-02-22 16:47:06 +01001508}
1509
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001510/* Test case where IuUP IP address announced by HNB and updated through MDCX
1511 * makes MGW select a new local IuUP address. HNBGW is expected to update the HNB
1512 * through RAB-Modify-Req. */
1513testcase TC_rab_assign_mgw_iuup_addr_chg() runs on test_CT {
1514 var ConnHdlr vc_conn;
1515 g_num_hnbs := 1;
1516 f_init();
1517 var template (value) TestHdlrParams pars := t_pars(3);
1518 /* Emulate change of local IuUP IP address after rx MDCX: */
1519 pars.mgcp_pars.mgw_conn_ran.mgw_rtp_ip_mdcx := "127.3.2.1";
1520
1521 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assignment), pars);
1522 vc_conn.done;
1523
1524 f_shutdown_helper();
1525}
1526
Daniel Willmann19b8d902022-01-05 09:12:34 +01001527/* Create an Iuh connection; send InitialUE; transceive data both directions */
1528friend function f_tc_ranap_bidir(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1529 f_init_handler(pars);
1530
1531 /* HNB -> MSC: InitialUE */
1532 f_iuh2iu_connect(f_build_initial_ue(g_pars));
1533
1534 /* MSC <- HNB: DirectTransfer */
1535 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1536 /* MSC -> HNB: DirectTransfer */
1537 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1538
1539 /* HNB <- MSC: CommonID */
1540 f_iu2iuh(ts_RANAP_CommonId(hex2oct(pars.imsi)));
1541}
1542testcase TC_ranap_cs_bidir() runs on test_CT {
1543 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001544 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001545 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001546
1547 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_bidir), t_pars(3));
1548 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001549
1550 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001551}
1552testcase TC_ranap_ps_bidir() runs on test_CT {
1553 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001554 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001555 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001556
1557 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_bidir), t_pars(4, true));
1558 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001559
1560 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001561}
1562
1563
1564private function f_tc_ranap_mo_disconnect(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1565 f_init_handler(pars);
1566
1567 /* HNB -> MSC: InitialUE */
1568 f_iuh2iu_connect(f_build_initial_ue(g_pars));
1569
1570 /* MSC <- HNB: DirectTransfer */
1571 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1572 /* MSC -> HNB: DirectTransfer */
1573 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1574
1575 /* MSC <- HNB: RUA disconnect */
1576 f_iuh2iu_disconnect(ts_RANAP_IuReleaseComplete, RUA_IEs.Cause:{misc:=processing_overload});
1577}
1578testcase TC_ranap_cs_mo_disconnect() runs on test_CT {
1579 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001580 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001581 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001582
1583 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_mo_disconnect), t_pars(5));
1584 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001585
1586 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001587}
1588testcase TC_ranap_ps_mo_disconnect() runs on test_CT {
1589 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001590 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001591 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001592
1593 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_mo_disconnect), t_pars(6));
1594 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001595
1596 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001597}
1598
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001599type record FTeid {
1600 HostName addr,
1601 OCT4 teid
1602}
1603
1604type record FTeids {
1605 FTeid local,
1606 FTeid remote
1607}
Daniel Willmann19b8d902022-01-05 09:12:34 +01001608
1609
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001610/* 'local' and 'remote' refer to the GTP information from the UPF's point of view:
1611 * HNB UPF CN
1612 * access.remote <---> access.local | core.local <---> core.remote
1613 */
1614type record GtpParameters {
1615 FTeids core,
1616 FTeids access
1617}
1618
1619/* HNB UPF CN
1620 * access.remote <---> access.local | core.local <---> core.remote
1621 * 127.0.0.4 127.0.0.3 127.0.0.2 127.0.0.1
1622 * 0x44004400 0x30303030 0x22002200 0x10101010
1623 */
1624template GtpParameters t_GtpParameters := {
1625 core := {
1626 local := {
1627 addr := "127.0.0.2",
1628 teid := '22002200'O
1629 },
1630 remote := {
1631 addr := "127.0.0.1",
1632 teid := '10101010'O
1633 }
1634 },
1635 access := {
1636 local := {
1637 addr := "127.0.0.3",
1638 teid := '30303030'O
1639 },
1640 remote := {
1641 addr := "127.0.0.4",
1642 teid := '44004400'O
1643 }
1644 }
1645}
1646
Neels Hofmeyr65499282023-04-25 02:31:51 +02001647private 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 +01001648{
1649 var PDU_PFCP rx;
Neels Hofmeyr65499282023-04-25 02:31:51 +02001650 timer T := wait_time;
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001651 T.start;
1652 alt {
1653 [] PFCP.receive(exp_rx) -> value rx {
1654 setverdict(pass);
1655 }
1656 [] PFCP.receive(PDU_PFCP:?) {
1657 setverdict(fail, "Got an unexpected PFCP message, was waiting for ", exp_rx);
1658 mtc.stop;
1659 }
1660 [] T.timeout {
1661 setverdict(fail, "Timeout waiting for PFCP ", exp_rx);
1662 mtc.stop;
1663 }
1664 }
1665 T.stop;
1666 return rx;
1667}
1668
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001669friend function f_tc_ps_rab_assignment_with_pfcp(charstring id, TestHdlrParams pars) runs on ConnHdlr {
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001670 var RANAP_PDU tx;
1671 var RANAP_PDU rx;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001672
1673 f_init_handler(pars);
1674
1675 f_pfcp_register();
1676
1677 var PDU_PFCP m;
1678 var Node_ID upf_node_id := valueof(ts_PFCP_Node_ID_fqdn("\07osmocom\03org"));
1679
Neels Hofmeyr65499282023-04-25 02:31:51 +02001680 m := f_pfcp_expect(tr_PFCP_Assoc_Setup_Req(), wait_time := 15.0);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001681 PFCP.send(ts_PFCP_Assoc_Setup_Resp(m.sequence_number, upf_node_id,
1682 ts_PFCP_Cause(REQUEST_ACCEPTED), 1234));
1683
1684 tx := f_build_initial_ue(g_pars);
1685 f_iuh2iu_connect(tx);
1686
1687 var GtpParameters gtp_pars := valueof(t_GtpParameters);
1688 var template RAB_SetupOrModifyList rab_sml;
1689
1690 /* Send RAB Assignment Request */
1691 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.core.remote.addr), gtp_pars.core.remote.teid);
1692 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1693 BSSAP.send(tx);
1694
1695 /* Expect PFCP Session Establishment Request. */
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001696 m := f_pfcp_expect(tr_PFCP_Session_Est_Req());
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001697 var F_SEID hnbgw_f_seid := m.message_body.pfcp_session_establishment_request.CP_F_SEID;
1698 var PFCP_Session_Establishment_Request serq := m.message_body.pfcp_session_establishment_request;
1699
1700 /* Acting as UPF, invent a new PFCP SEID to send to HNBGW. Respond to the Session Establishment.
1701 * The PFCP response must have the same sequence_number as the request. */
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001702 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 +02001703 var template PDU_PFCP r := ts_PFCP_Session_Est_Resp(m.sequence_number, upf_node_id, hnbgw_f_seid.seid);
1704 r.message_body.pfcp_session_establishment_response := {
1705 offending_ie := omit,
1706 UP_F_SEID := up_f_seid,
1707 created_PDR_list := {
1708 ts_PFCP_Created_PDR(pdr_id := serq.create_PDR_list[0].grouped_ie.pdr_id,
1709 local_F_TEID := ts_PFCP_F_TEID_ipv4(gtp_pars.core.local.teid,
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001710 f_inet_addr(gtp_pars.core.local.addr))),
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001711 ts_PFCP_Created_PDR(pdr_id := serq.create_PDR_list[1].grouped_ie.pdr_id,
1712 local_F_TEID := ts_PFCP_F_TEID_ipv4(gtp_pars.access.local.teid,
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001713 f_inet_addr(gtp_pars.access.local.addr)))
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001714 },
1715 load_control_information := omit,
1716 overload_control_information := omit,
1717 node_list := omit,
1718 failed_rule_id := omit,
1719 created_traffic_endpoint_list := omit
1720 };
1721 PFCP.send(r);
1722
1723 /* Expect on Iuh: RAB Assignment Request with IP/port from PFCP Session Est Resp */
1724 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.local.addr),
1725 gtp_pars.access.local.teid);
1726 rx := valueof(ts_RANAP_RabAssReq(rab_sml));
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001727 f_rua_expect(rx);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001728
1729 /* Send back RAB Assignment Response via Iuh */
1730 var template RAB_SetupOrModifiedList rab_smdl;
1731 rab_smdl := ts_RAB_SMdL_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.remote.addr),
1732 gtp_pars.access.remote.teid);
1733 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1734 RUA.send(tx);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001735
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001736 m := f_pfcp_expect(tr_PFCP_Session_Mod_Req(up_f_seid.seid));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001737 r := ts_PFCP_Session_Mod_Resp(m.sequence_number, hnbgw_f_seid.seid);
1738 PFCP.send(r);
1739
1740 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 +01001741 f_bssap_expect(tr_RANAP_RabAssResp(rab_smdl));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001742
1743 f_sleep(2.0);
1744 tx := valueof(ts_RANAP_IuReleaseCommand(ts_RanapCause_om_intervention));
1745 f_iu2iuh(tx);
1746
1747 tx := valueof(ts_RANAP_IuReleaseComplete());
1748 f_iuh2iu(tx);
1749
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001750 m := f_pfcp_expect(tr_PFCP_Session_Del_Req(up_f_seid.seid));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001751 PFCP.send(ts_PFCP_Session_Del_Resp(m.sequence_number, hnbgw_f_seid.seid));
1752
1753 f_sleep(2.0);
1754}
1755
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001756testcase TC_ps_rab_assignment_with_pfcp() runs on test_CT {
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001757 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001758 g_num_hnbs := 1;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001759 f_init();
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001760 f_sleep(1.0);
1761
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001762 vc_conn := f_start_handler_with_pars(refers(f_tc_ps_rab_assignment_with_pfcp), t_pars(7, ps_domain := true));
1763 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001764
1765 f_shutdown_helper();
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001766}
1767
1768altstep as_disallow_pfcp() runs on ConnHdlr {
1769 [] PFCP.receive(PDU_PFCP:?) {
1770 setverdict(fail, "Received PFCP message, but no PFCP communication expected");
1771 mtc.stop;
1772 }
1773}
1774
1775friend function f_tc_ps_rab_assignment_without_pfcp(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1776 var RANAP_PDU tx;
1777 var RANAP_PDU rx;
1778 timer T := 5.0;
1779
1780 f_init_handler(pars);
1781
1782 f_pfcp_register();
1783 activate(as_disallow_pfcp());
1784
1785 tx := f_build_initial_ue(g_pars);
1786 f_iuh2iu_connect(tx);
1787
1788 var GtpParameters gtp_pars := valueof(t_GtpParameters);
1789 var template RAB_SetupOrModifyList rab_sml;
1790
1791 /* Send RAB Assignment Request */
1792 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.core.remote.addr), gtp_pars.core.remote.teid);
1793 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1794 BSSAP.send(tx);
1795
1796 /* Expect on Iuh: unmodified RAB Assignment Request */
1797 rx := valueof(ts_RANAP_RabAssReq(rab_sml));
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001798 f_rua_expect(rx);
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001799
1800 /* Send back RAB Assignment Response via Iuh */
1801 var template RAB_SetupOrModifiedList rab_smdl;
1802 rab_smdl := ts_RAB_SMdL_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.remote.addr),
1803 gtp_pars.access.remote.teid);
1804 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1805 RUA.send(tx);
1806
1807 /* Expect on IuPS: unmodified RAB Assignment Response */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +01001808 f_bssap_expect(tr_RANAP_RabAssResp(rab_smdl));
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001809
1810 f_sleep(2.0);
1811 tx := valueof(ts_RANAP_IuReleaseCommand(ts_RanapCause_om_intervention));
1812 f_iu2iuh(tx);
1813
1814 tx := valueof(ts_RANAP_IuReleaseComplete());
1815 f_iuh2iu(tx);
1816
1817 f_sleep(2.0);
1818}
1819
1820testcase TC_ps_rab_assignment_without_pfcp() runs on test_CT {
1821 var ConnHdlr vc_conn;
1822 f_init();
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001823 f_sleep(1.0);
1824
1825 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 +02001826 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001827
1828 f_shutdown_helper();
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001829}
Daniel Willmann19b8d902022-01-05 09:12:34 +01001830
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02001831/* Default list of counters for a 'cn' entity to test the cnpool feature. */
1832const CounterNameVals counternames_cnpool := {
1833 { "cnpool:subscr:new", 0 },
1834 { "cnpool:subscr:known", 0 },
1835 { "cnpool:subscr:reattach", 0 },
1836 { "cnpool:subscr:attach_lost", 0 },
1837 { "cnpool:subscr:paged", 0 }
1838};
1839private function f_ctrs_cn_init(boolean ps_domain, integer cn_count := 0,
1840 CounterNameVals counternames := counternames_cnpool) runs on test_CT {
1841 if (ps_domain) {
1842 g_ctr_cn_node_name := "sgsn";
1843 if (cn_count == 0) {
1844 cn_count := NUM_SGSN;
1845 }
1846 } else {
1847 g_ctr_cn_node_name := "msc";
1848 if (cn_count == 0) {
1849 cn_count := NUM_MSC;
1850 }
1851 }
1852 g_ctr_cn := f_counter_name_vals_get_n(IPA_CTRL, g_ctr_cn_node_name, cn_count, counternames);
1853 log("initial " & g_ctr_cn_node_name & " rate counters: ", g_ctr_cn);
1854}
1855
1856/* f_ctrs_cn_init();
1857 * f_do_thing(on_cn := 0);
1858 * f_do_thing(on_cn := 0);
1859 * f_do_other(on_cn := 1);
1860 * f_ctrs_cn_add(0, "thing", 2);
1861 * f_ctrs_cn_add(1, "other");
1862 * f_ctrs_cn_verify();
1863 */
1864private function f_ctrs_cn_verify() runs on test_CT {
1865 log("verifying", g_ctr_cn_node_name, " rate counters: ", g_ctr_cn);
1866 f_counter_name_vals_expect_n(IPA_CTRL, g_ctr_cn_node_name, g_ctr_cn);
1867}
1868
1869/* convenience: f_ctrs_cn_add() and f_ctrs_cn_verify() in one call.
1870 * f_ctrs_cn_init();
1871 * f_do_thing(on_cn := 0);
1872 * f_do_thing(on_cn := 0);
1873 * f_do_thing(on_cn := 0);
1874 * f_ctrs_cn_expect(0, "thing", 3);
1875 */
1876private function f_ctrs_cn_expect(integer cn_nr, charstring countername, integer val := 1) runs on test_CT {
1877 f_ctrs_cn_add(cn_nr, countername, val);
1878 f_ctrs_cn_verify();
1879}
1880
1881private function f_ctrs_cn_add(integer cn_nr, charstring countername, integer val := 1) runs on test_CT {
1882 f_counter_name_vals_list_add(g_ctr_cn, cn_nr, countername, val);
1883}
1884
1885private function f_perform_compl_l3(octetstring nas, boolean do_clear := true, boolean expect_iu_l3 := true)
1886runs on ConnHdlr {
1887 timer T := 10.0;
1888
1889 /* create an expect on the Iu side for the random NAS portion */
1890 if (g_pars.expect_separate_sccp_cr) {
1891 f_ran_register_sccp_cr_without_payload();
1892 } else {
1893 f_ran_register_exp(nas);
1894 }
1895
1896 /* send Connect via Iuh (creating a RUA connection) */
1897 var RANAP_PDU tx := f_build_initial_ue_with_nas(g_pars, nas);
1898 RUA.send(RUA_Conn_Req:{g_pars.ps_domain, tx});
1899
1900 if (expect_iu_l3) {
1901 /* Expect same message to arrive at CN */
1902 f_bssap_expect(tx);
1903 }
1904}
1905
1906private function f_tc_cnpool_compl_l3(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1907 f_init_handler(pars);
1908 f_perform_compl_l3(g_pars.nas_pdu);
1909}
1910
1911private function f_TC_cnpool_compl_l3(boolean ps_domain, octetstring nas_pdu, integer cn_nr,
1912 template (omit) charstring inc_countername := omit) runs on test_CT {
1913 var ConnHdlr vc_conn;
1914 var template (value) TestHdlrParams pars := t_pars(0, ps_domain := ps_domain, cn_nr := cn_nr);
1915 pars.nas_pdu := nas_pdu;
1916 log("XXX ", pars);
1917 vc_conn := f_start_handler_with_pars(refers(f_tc_cnpool_compl_l3), pars);
1918 vc_conn.done;
1919
1920 if (not istemplatekind(inc_countername, "omit")) {
1921 f_ctrs_cn_expect(cn_nr, valueof(inc_countername));
1922 }
1923}
1924
1925function f_TC_cnpool_compl_l3_list(boolean ps_domain, ro_octetstring compl3, Osmocom_Types.ro_integer cn_nrs,
1926 charstring inc_countername) runs on test_CT {
1927 var integer n := lengthof(compl3);
1928 if (n < lengthof(cn_nrs)) {
1929 n := lengthof(cn_nrs);
1930 }
1931 for (var integer i := 0; i < n; i := i + 1) {
1932 var integer cn_nr := cn_nrs[i mod lengthof(cn_nrs)];
1933 f_TC_cnpool_compl_l3(ps_domain, compl3[i mod lengthof(compl3)], cn_nr, inc_countername);
1934 }
1935}
1936
1937type enumerated Compl3Type {
1938 /* CS */
1939 LU,
1940 CMSERV,
1941 PAGRESP,
1942 IMSIDETACH,
1943
1944 /* PS */
1945 ATTACHREQ,
1946 RAUREQ,
1947 DETREQ
1948};
1949
1950private function f_gen_one_compl_l3(Compl3Type compl3type, template (value) MobileIdentityLV mi,
1951 integer ps_nri := -1
1952 ) return octetstring
1953{
1954 /* CS */
1955 if (compl3type == LU) {
1956 return enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(mi), '00F110'O)));
1957 }
1958 if (compl3type == CMSERV) {
1959 return enc_PDU_ML3_MS_NW(valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(mi))));
1960 }
1961 if (compl3type == PAGRESP) {
1962 return enc_PDU_ML3_MS_NW(valueof(ts_PAG_RESP(valueof(mi))));
1963 }
1964 if (compl3type == IMSIDETACH) {
1965 return enc_PDU_ML3_MS_NW(valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(mi))));
1966 }
1967
1968 /* PS */
1969 var template (omit) NetworkResourceIdentifierContainerTLV nri := omit;
1970 if (ps_nri >= 0) {
1971 nri := valueof(ts_GMM_NRI(ps_nri));
1972 }
1973
1974 if (compl3type == ATTACHREQ) {
1975 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_ATTACH_REQ(valueof(mi), f_RAI('001'H, '01'H, '2a2a'O, '17'O),
1976 nri := nri)));
1977 }
1978 if (compl3type == RAUREQ) {
1979 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_RAU_REQ(valueof(mi), GPRS_UPD_T_PERIODIC,
1980 f_RAI('001'H, '01'H, '2a2a'O, '17'O),
1981 nri := nri)));
1982 }
1983 if (compl3type == DETREQ) {
1984 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_DET_REQ_MO_mi(c_GMM_DTT_MO_GPRS, power_off := false,
1985 p_tmsi := valueof(ts_MI_TLV(mi.mobileIdentityV)))));
1986 }
1987
1988 setverdict(fail, "unknown complete layer 3 type");
1989 mtc.stop;
1990}
1991
1992type record of Compl3Type ro_Compl3Type;
1993type record of MobileIdentityLV ro_MobileIdentityLV;
1994type record of octetstring ro_octetstring;
1995
1996/* Generate a list of n Complete Layer 3 NAS PDUs,
1997 * rotating through the message kinds listed in 'types' and the mobile identities in mis.
1998 */
1999private function f_gen_compl_l3(ro_Compl3Type types, ro_MobileIdentityLV mis, integer n) return ro_octetstring
2000{
2001 var ro_octetstring res := {};
2002 for (var integer i := 0; i < n; i := i + 1) {
2003 var integer ti := i mod lengthof(types);
2004 var integer mi := i mod lengthof(mis);
2005 res[i] := f_gen_one_compl_l3(types[ti], mis[mi]);
2006 }
2007 return res;
2008}
2009
2010private function f_gen_mi_imsi(integer n) return MobileIdentityLV
2011{
2012 return valueof(ts_MI_IMSI_LV(f_gen_imsi(n)));
2013}
2014
2015private function f_gen_mi_imsis(integer n) return ro_MobileIdentityLV
2016{
2017 var ro_MobileIdentityLV mis := {};
2018 for (var integer i := 0; i < n; i := i + 1) {
2019 mis[i] := f_gen_mi_imsi(n);
2020 }
2021 return mis;
2022}
2023
2024function f_vty_set_roundrobin_next(TELNETasp_PT VTY, boolean ps_domain, integer cn_nr)
2025{
2026 var charstring msc_sgsn;
2027 if (ps_domain) {
2028 msc_sgsn := "sgsn";
2029 } else {
2030 msc_sgsn := "msc";
2031 }
2032 f_vty_transceive(VTY, "cnpool roundrobin next " & msc_sgsn & " " & int2str(cn_nr));
2033}
2034
2035private function f_gen_compl3_by_domain(boolean ps_domain, integer n, template (omit) ro_MobileIdentityLV mis := omit) return ro_octetstring{
2036 var ro_Compl3Type types;
2037 if (ps_domain) {
2038 types := { ATTACHREQ, RAUREQ, DETREQ };
2039 } else {
2040 types := { LU, CMSERV, PAGRESP, IMSIDETACH };
2041 }
2042 if (istemplatekind(mis, "omit")) {
2043 mis := f_gen_mi_imsis(n);
2044 }
2045 return f_gen_compl_l3(types, valueof(mis), n);
2046}
2047
2048/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
2049testcase TC_mscpool_L3Compl_on_1_cnlink() runs on test_CT {
2050 f_TC_cnpool_L3Compl_on_1_cnlink(ps_domain := false);
2051}
2052testcase TC_sgsnpool_L3Compl_on_1_cnlink() runs on test_CT {
2053 f_TC_cnpool_L3Compl_on_1_cnlink(ps_domain := true);
2054}
2055function f_TC_cnpool_L3Compl_on_1_cnlink(boolean ps_domain) runs on test_CT {
2056
2057 f_init();
2058
2059 f_ctrs_cn_init(ps_domain := ps_domain);
2060
2061 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 4);
2062 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {0, 0, 0, 0}, "cnpool:subscr:new");
2063
2064 f_shutdown_helper();
2065}
2066
2067/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
2068testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
2069 f_TC_cnpool_L3Complete_by_imsi_round_robin(ps_domain := false);
2070}
2071testcase TC_sgsnpool_L3Complete_no_nri_round_robin() runs on test_CT {
2072 f_TC_cnpool_L3Complete_by_imsi_round_robin(ps_domain := true);
2073}
2074function f_TC_cnpool_L3Complete_by_imsi_round_robin(boolean ps_domain) runs on test_CT {
2075
2076 f_init(nr_msc := 2, nr_sgsn := 2);
2077 f_sleep(1.0);
2078
2079 /* Control which MSC gets chosen next by the round-robin, otherwise
2080 * would be randomly affected by which other tests ran before this. */
2081 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2082
2083 f_ctrs_cn_init(ps_domain := ps_domain);
2084
2085 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2086
2087 f_TC_cnpool_compl_l3_list(ps_domain, compl3,
2088 /* Third Complete Layer 3 wraps back to msc 0 */
2089 cn_nrs := {0, 1, 0},
2090 inc_countername := "cnpool:subscr:new");
2091
2092 f_shutdown_helper();
2093}
2094
2095/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain a NULL-NRI (0, 1)
2096 * (configured in osmo-hnbgw.cfg). */
2097testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
2098 f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(ps_domain := false, nri_val := 0);
2099}
2100/* 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
2101 * than that. */
2102testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
2103 f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(ps_domain := false, nri_val := 1);
2104}
2105function f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(boolean ps_domain, integer nri_val) runs on test_CT {
2106
2107 f_init(nr_msc := 2, nr_sgsn := 2);
2108 f_sleep(1.0);
2109
2110 /* Control which MSC gets chosen next by the round-robin, otherwise
2111 * would be randomly affected by which other tests ran before this. */
2112 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2113
2114 f_ctrs_cn_init(ps_domain := ps_domain);
2115
2116 var ro_MobileIdentityLV mis := { valueof(ts_MI_TMSI_NRI_LV(nri_val)) };
2117 var ro_octetstring compl3;
2118 if (ps_domain) {
2119 compl3 := {
2120 f_gen_one_compl_l3(ATTACHREQ, mis[0], nri_val)
2121 };
2122 } else {
2123 compl3 := f_gen_compl_l3({LU}, mis, 1);
2124 }
2125
2126 f_TC_cnpool_compl_l3_list(ps_domain, compl3,
2127 /* The third Complete Layer 3 wraps back to msc 0 */
2128 {0, 1, 0},
2129 "cnpool:subscr:reattach");
2130 f_shutdown_helper();
2131}
2132
2133/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
2134 * assigned to any MSC (configured in osmo-hnbgw.cfg). */
2135testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
2136 f_TC_cnpool_L3Complete_by_tmsi_unassigned_nri_round_robin(ps_domain := false);
2137}
2138function f_TC_cnpool_L3Complete_by_tmsi_unassigned_nri_round_robin(boolean ps_domain) runs on test_CT {
2139
2140 f_init(nr_msc := 2, nr_sgsn := 2);
2141 f_sleep(1.0);
2142
2143 /* Control which MSC gets chosen next by the round-robin, otherwise
2144 * would be randomly affected by which other tests ran before this. */
2145 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2146
2147 f_ctrs_cn_init(ps_domain := ps_domain);
2148
2149 /* 3 NRIs that are not assigned to any MSC */
2150 var ro_MobileIdentityLV mis := {
2151 valueof(ts_MI_TMSI_NRI_LV(1000)),
2152 valueof(ts_MI_TMSI_NRI_LV(768)),
2153 valueof(ts_MI_TMSI_NRI_LV(819))
2154 };
2155
2156 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2157 f_TC_cnpool_compl_l3_list(ps_domain, compl3, { 0, 1, 0 }, "cnpool:subscr:new");
2158
2159 f_shutdown_helper();
2160}
2161
2162/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
2163 * assigned to a CN link that is currently not connected (configured in osmo-hnbgw.cfg). */
2164testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
2165 f_TC_cnpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin(ps_domain := false);
2166}
2167function f_TC_cnpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin(boolean ps_domain) runs on test_CT {
2168
2169 f_init(nr_msc := 2, nr_sgsn := 2);
2170 f_sleep(1.0);
2171
2172 /* Control which MSC gets chosen next by the round-robin, otherwise
2173 * would be randomly affected by which other tests ran before this. */
2174 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2175
2176 f_ctrs_cn_init(ps_domain := ps_domain);
2177
2178 /* 3 NRIs that are assigned to an unconnected MSC */
2179 var ro_MobileIdentityLV mis := {
2180 valueof(ts_MI_TMSI_NRI_LV(512)),
2181 valueof(ts_MI_TMSI_NRI_LV(767)),
2182 valueof(ts_MI_TMSI_NRI_LV(750))
2183 };
2184
2185 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2186
2187 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0);
2188 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2189 f_ctrs_cn_add(0, "cnpool:subscr:new");
2190 f_ctrs_cn_verify();
2191
2192 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 1);
2193 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2194 f_ctrs_cn_add(1, "cnpool:subscr:new");
2195 f_ctrs_cn_verify();
2196
2197 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 0);
2198 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2199 f_ctrs_cn_add(0, "cnpool:subscr:new");
2200 f_ctrs_cn_verify();
2201
2202 f_shutdown_helper();
2203}
2204
2205/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
2206 * osmo-hnbgw.cfg). */
2207testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
2208 f_TC_cnpool_L3Complete_valid_nri_1(ps_domain := false);
2209}
2210testcase TC_sgsnpool_L3Complete_valid_nri_1() runs on test_CT {
2211 f_TC_cnpool_L3Complete_valid_nri_1(ps_domain := true);
2212}
2213function f_TC_cnpool_L3Complete_valid_nri_1(boolean ps_domain) runs on test_CT {
2214
2215 f_init(nr_msc := 2, nr_sgsn := 2);
2216 f_sleep(1.0);
2217
2218 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
2219 * this is not using round-robin. */
2220 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2221
2222 f_ctrs_cn_init(ps_domain := ps_domain);
2223
2224 var ro_octetstring compl3;
2225
2226 /* 3 NRIs of the second MSC's range (256-511) */
2227 var ro_MobileIdentityLV mis := {
2228 valueof(ts_MI_TMSI_NRI_LV(256)),
2229 valueof(ts_MI_TMSI_NRI_LV(260)),
2230 valueof(ts_MI_TMSI_NRI_LV(511))
2231 };
2232 if (ps_domain) {
2233 compl3 := {
2234 f_gen_one_compl_l3(RAUREQ, mis[0], 256),
2235 f_gen_one_compl_l3(RAUREQ, mis[1], 260),
2236 f_gen_one_compl_l3(RAUREQ, mis[2], 511)
2237 };
2238 } else {
2239 compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2240 }
2241
2242 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {1, 1, 1}, "cnpool:subscr:known");
2243
2244 f_shutdown_helper();
2245}
2246
2247/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-hnbgw.cfg),
2248 * while a round-robin remains unaffected by that. */
2249testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
2250 f_TC_cnpool_L3Complete_valid_nri_2(ps_domain := false);
2251}
2252testcase TC_sgsnpool_L3Complete_valid_nri_2() runs on test_CT {
2253 f_TC_cnpool_L3Complete_valid_nri_2(ps_domain := true);
2254}
2255function f_TC_cnpool_L3Complete_valid_nri_2(boolean ps_domain) runs on test_CT {
2256
2257 f_init(nr_msc := 3, nr_sgsn := 3);
2258 f_sleep(1.0);
2259
2260 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
2261 * this is not using round-robin. */
2262 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 1);
2263
2264 f_ctrs_cn_init(ps_domain := ps_domain);
2265
2266 var ro_octetstring compl3;
2267
2268 /* 2 NRIs of the third MSC's range (512-767) */
2269 var ro_MobileIdentityLV mis := {
2270 valueof(ts_MI_TMSI_NRI_LV(512)),
2271 valueof(ts_MI_TMSI_NRI_LV(678))
2272 };
2273 if (ps_domain) {
2274 compl3 := {
2275 f_gen_one_compl_l3(ATTACHREQ, mis[0], 512),
2276 f_gen_one_compl_l3(ATTACHREQ, mis[1], 678)
2277 };
2278 } else {
2279 compl3 := f_gen_compl3_by_domain(ps_domain, 2, mis);
2280 }
2281
2282 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {2, 2}, "cnpool:subscr:known");
2283
2284 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
2285 f_TC_cnpool_compl_l3_list(ps_domain, f_gen_compl3_by_domain(ps_domain, 1), {1}, "cnpool:subscr:new");
2286
2287 f_shutdown_helper();
2288}
2289
2290/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
2291testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
2292 f_TC_cnpool_nri_from_other_PLMN(ps_domain := false);
2293}
2294testcase TC_sgsnpool_nri_from_other_PLMN() runs on test_CT {
2295 f_TC_cnpool_nri_from_other_PLMN(ps_domain := true);
2296}
2297function f_TC_cnpool_nri_from_other_PLMN(boolean ps_domain) runs on test_CT {
2298
2299 f_init(nr_msc := 3, nr_sgsn := 3);
2300 f_sleep(1.0);
2301
2302 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
2303 * instead, and hits msc 0. */
2304 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2305
2306 f_ctrs_cn_init(ps_domain := ps_domain);
2307
2308 var ro_octetstring compl3;
2309
2310 var ro_MobileIdentityLV mis := {
2311 valueof(ts_MI_TMSI_NRI_LV(260)),
2312 valueof(ts_MI_TMSI_NRI_LV(555))
2313 };
2314 if (ps_domain) {
2315 compl3 := {
2316 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-hnbgw.cfg */
2317 enc_PDU_L3_MS_SGSN(valueof(ts_GMM_ATTACH_REQ(mis[0], f_RAI('999'H, '99'H, '2a2a'O,
2318 '17'O),
2319 nri := ts_GMM_NRI(260)
2320 ))),
2321 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
2322 f_gen_one_compl_l3(ATTACHREQ, mis[1], 555)
2323 }
2324 } else {
2325 compl3 := {
2326 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-hnbgw.cfg */
2327 enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, mis[0], '99F999'O))),
2328 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
2329 enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, mis[1], '00F110'O)))
2330 };
2331 }
2332
2333 /* Foreign NRI: roundrobin */
2334 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2335
2336 /* Local NRI: matching msc */
2337 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 2, inc_countername := "cnpool:subscr:known");
2338
2339 f_shutdown_helper();
2340}
2341
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02002342/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
2343 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
2344friend function f_tc_mscpool_paging_imsi(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2345 f_init_handler(pars);
2346
2347 var hexstring imsi := '001010000000123'H;
2348 var RANAP_IEs.CN_DomainIndicator domain_ind;
2349 if (pars.ps_domain) {
2350 domain_ind := ps_domain;
2351 } else {
2352 domain_ind := cs_domain;
2353 }
2354 var template (value) RANAP_PDU paging := ts_RANAP_Paging(domain_ind, imsi_hex2oct(imsi));
2355 BSSAP.send(ts_RANAP_UNITDATA_req(pars.sccp_addr_hnbgw, pars.sccp_addr_msc, paging));
2356 /* TODO: Expect RUA ConnectionlessTransfer Paging (on all HNB).
2357 * We could verify the Paging sent from osmo-hnbgw to RUA with some effort,
2358 * but, this test does not care whether the Paging was forwarded to RUA or not, only that osmo-hnbgw *received*
2359 * the Paging. In the CN pool decisions, osmo-hnbgw should match up Paging Response to an earlier Paging.
2360 */
2361
2362 f_sleep(1.0);
2363
2364 /* Despite the round robin pointing at the second MSC ('roundrobin next msc 1'), the earlier Paging for the same IMSI
2365 * causes this Paging Response to go to the first MSC ('msc 0'). */
2366 f_perform_compl_l3(f_gen_one_compl_l3(PAGRESP, ts_MI_IMSI_LV(imsi)));
2367 f_sleep(1.0);
2368}
2369
2370testcase TC_mscpool_paging_imsi() runs on test_CT {
2371 f_init(nr_msc := 3);
2372 f_sleep(1.0);
2373
2374 var boolean ps_domain := false;
2375
2376 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
2377 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
2378 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2379
2380 f_ctrs_cn_init(ps_domain := ps_domain);
2381
2382 var ConnHdlr vc_conn1;
2383 var template (value) TestHdlrParams pars1 := t_pars(0, ps_domain := ps_domain, cn_nr := 0);
2384 pars1.sccp_addr_hnbgw := g_cn[valueof(pars1.cn_idx)].sccp_addr_peer;
2385 pars1.sccp_addr_msc := g_cn[valueof(pars1.cn_idx)].sccp_addr_own;
2386 vc_conn1 := f_start_handler_with_pars(refers(f_tc_mscpool_paging_imsi), pars1);
2387 vc_conn1.done;
2388 f_ctrs_cn_expect(0, "cnpool:subscr:paged");
2389 f_shutdown_helper();
2390}
2391
2392/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
2393 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
2394friend function f_tc_mscpool_paging_tmsi(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2395 f_init_handler(pars);
2396
2397 var hexstring imsi := '001010000000124'H;
2398 var integer nri_v := 300; /* <-- second MSC's NRI */
2399 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
2400
2401 var RANAP_IEs.CN_DomainIndicator domain_ind;
2402 if (pars.ps_domain) {
2403 domain_ind := ps_domain;
2404 } else {
2405 domain_ind := cs_domain;
2406 }
2407 var template (value) RANAP_PDU paging := ts_RANAP_Paging_temp_id(domain_ind, imsi_hex2oct(imsi),
2408 ts_RANAP_TemporaryUE_ID_TMSI(tmsi));
2409 BSSAP.send(ts_RANAP_UNITDATA_req(pars.sccp_addr_hnbgw, pars.sccp_addr_msc, paging));
2410 /* TODO: Expect RUA ConnectionlessTransfer Paging (on all HNB).
2411 * We could verify the Paging sent from osmo-hnbgw to RUA with some effort,
2412 * but, this test does not care whether the Paging was forwarded to RUA or not, only that osmo-hnbgw *received*
2413 * the Paging. In the CN pool decisions, osmo-hnbgw should match up Paging Response to an earlier Paging.
2414 */
2415
2416 f_sleep(1.0);
2417
2418 /* Despite the round robin pointing at the third MSC ('roundrobin next msc 2'), the earlier Paging for the same
2419 * TMSI causes this Paging Response to go to the first MSC ('msc 0'). */
2420 f_perform_compl_l3(f_gen_one_compl_l3(PAGRESP, ts_MI_TMSI_NRI_LV(nri_v)));
2421 f_sleep(1.0);
2422}
2423testcase TC_mscpool_paging_tmsi() runs on test_CT {
2424 f_init(nr_msc := 3);
2425 f_sleep(1.0);
2426
2427 var boolean ps_domain := false;
2428
2429 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
2430 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
2431 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2432
2433 f_ctrs_cn_init(ps_domain := ps_domain);
2434
2435 var ConnHdlr vc_conn1;
2436 var template (value) TestHdlrParams pars1 := t_pars(0, ps_domain := ps_domain, cn_nr := 0);
2437 pars1.sccp_addr_hnbgw := g_cn[valueof(pars1.cn_idx)].sccp_addr_peer;
2438 pars1.sccp_addr_msc := g_cn[valueof(pars1.cn_idx)].sccp_addr_own;
2439 vc_conn1 := f_start_handler_with_pars(refers(f_tc_mscpool_paging_tmsi), pars1);
2440 vc_conn1.done;
2441 f_ctrs_cn_expect(0, "cnpool:subscr:paged");
2442 f_shutdown_helper();
2443}
2444
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002445/* For round-robin, skip a CN link that has 'no allow-attach' set. */
2446testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
2447
2448 f_init(nr_msc := 3);
2449 f_sleep(1.0);
2450
2451 var boolean ps_domain := false;
2452
2453 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
2454 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, {true, false, true});
2455
2456 /* Control which MSC gets chosen next by the round-robin, otherwise
2457 * would be randomly affected by which other tests ran before this. */
2458 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2459
2460 f_ctrs_cn_init(ps_domain := ps_domain);
2461
2462 f_TC_cnpool_compl_l3_list(ps_domain, f_gen_compl3_by_domain(ps_domain, 3),
2463 /* msc 1 is skipped */
2464 {0, 2, 0},
2465 "cnpool:subscr:new");
2466
2467 f_shutdown_helper();
2468}
2469
2470/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
2471 * TMSI NRI. */
2472testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
2473
2474 f_init(nr_msc := 3);
2475 f_sleep(1.0);
2476
2477 var boolean ps_domain := false;
2478
2479 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
2480 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, {true, false, true});
2481
2482 /* Control which MSC gets chosen next by the round-robin, otherwise
2483 * would be randomly affected by which other tests ran before this. */
2484 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2485
2486 f_ctrs_cn_init(ps_domain := ps_domain);
2487
2488 var ro_MobileIdentityLV mis := {
2489 valueof(ts_MI_TMSI_NRI_LV(260)),
2490 valueof(ts_MI_IMSI_LV('001010000000002'H)),
2491 valueof(ts_MI_IMSI_LV('001010000000003'H))
2492 };
2493
2494 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2495
2496 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
2497 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 1, inc_countername := "cnpool:subscr:known");
2498
2499 /* Normal round robin skips msc 1, because it has 'no allow-attach' */
2500 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2501 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 2, inc_countername := "cnpool:subscr:new");
2502
2503 f_shutdown_helper();
2504}
2505
2506/* When a peer point-code gets an SCCP N-PCSTATE saying it is unreachable, immediately mark the CN link as unusable. */
2507testcase TC_mscpool_sccp_n_pcstate_detaches_cnlink() runs on test_CT {
2508 f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(ps_domain := false);
2509}
2510testcase TC_sgsnpool_sccp_n_pcstate_detaches_cnlink() runs on test_CT {
2511 f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(ps_domain := true);
2512}
2513function f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(boolean ps_domain) runs on test_CT
2514{
2515
2516 f_init(nr_msc := 2, nr_sgsn := 2);
2517 f_sleep(1.0);
2518
2519 /* Control which MSC gets chosen next by the round-robin, otherwise
2520 * would be randomly affected by which other tests ran before this. */
2521 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2522
2523 f_ctrs_cn_init(ps_domain := ps_domain);
2524
2525 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2526
2527 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2528 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2529
2530 f_logp(HNBGWVTY, "disconnecting msc0");
2531 f_cn_idx_disconnect(f_cn_idx(ps_domain, 0));
2532
2533 /* Now round-robin would wrap to the first MSC, but since the first MSC is disconnected, it wraps around to the
2534 * second. */
2535 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2536
2537 f_shutdown_helper();
2538}
2539
2540/* When a CN link point-code gets an SCCP N-PCSTATE saying it is now reachable, immediately trigger RESET and bring up the
2541 * MSC. */
2542testcase TC_mscpool_sccp_n_pcstate_attaches_cnlink() runs on test_CT {
2543 f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(ps_domain := false);
2544}
2545testcase TC_sgsnpool_sccp_n_pcstate_attaches_cnlink() runs on test_CT {
2546 f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(ps_domain := true);
2547}
2548function f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(boolean ps_domain) runs on test_CT
2549{
2550 f_init(nr_msc := 1, nr_sgsn := 1);
2551 f_sleep(1.0);
2552
2553 /* Control which MSC gets chosen next by the round-robin, otherwise
2554 * would be randomly affected by which other tests ran before this. */
2555 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2556
2557 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2558
2559 f_ctrs_cn_init(ps_domain := ps_domain);
2560
2561 /* There is only one MSC, round robin stays on msc0 */
2562 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2563 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[1], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2564
2565 f_logp(HNBGWVTY, "connecting cnlink 1");
2566 f_cn_nr_init(ps_domain, 1);
2567 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, { true, true });
2568 f_sleep(1.0);
2569
2570 /* This time round-robin wraps to the second MSC, because it is now online. */
2571 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[2], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2572
2573 f_shutdown_helper();
2574}
2575
Neels Hofmeyrd019cc02023-06-02 16:31:23 +02002576private function f_vty_add_sccp_addr(TELNETasp_PT pt, charstring addr_name, charstring pc, integer cs7_nr := 0)
2577{
2578 f_vty_enter_config(pt);
2579 f_vty_transceive(pt, "cs7 instance 0");
2580 f_vty_transceive(pt, "sccp-address " & addr_name);
2581 f_vty_transceive(pt, "point-code " & pc);
2582 f_vty_transceive(pt, "end");
2583}
2584
2585private function f_vty_set_cnlink_addr(TELNETasp_PT pt, charstring cnlink_and_nr, charstring addr_name)
2586{
2587 f_vty_enter_config(pt);
2588 f_vty_transceive(pt, cnlink_and_nr);
2589 f_vty_transceive(pt, "remote-addr " & addr_name);
2590 f_vty_transceive(pt, "end");
2591}
2592
2593private function f_vty_apply_sccp(TELNETasp_PT pt)
2594{
2595 f_vty_enter_config(pt);
2596 f_vty_transceive(pt, "apply sccp");
2597 f_vty_transceive(pt, "end");
2598}
2599
2600template (present) RUA_Disc_Req tr_RUA_Disc_Req := {
2601 ranap := ?,
2602 cause := ?
2603};
2604
2605/* With a cnlink up, change the SCCP address, and verify that it restarts upon vty 'apply sccp' */
2606private function f_tc_apply_sccp(charstring id, TestHdlrParams pars) runs on ConnHdlr
2607{
2608 f_init_handler(pars);
2609 f_perform_compl_l3(f_gen_compl3_by_domain(pars.ps_domain, 1)[0]);
2610
2611 f_sleep(1.0);
2612 f_logp(HNBGWVTY, "Changing SCCP address, don't apply yet");
2613
2614 f_vty_add_sccp_addr(HNBGWVTY, "msc-foo", "0.42.4");
2615 f_vty_set_cnlink_addr(HNBGWVTY, "msc 0", "msc-foo");
2616
2617 /* No effect yet, link still open both ways */
2618 f_sleep(1.0);
2619 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
2620 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
2621
2622 f_logp(HNBGWVTY, "Apply SCCP address changes");
2623 f_vty_apply_sccp(HNBGWVTY);
2624
2625 /* We modified the SCCP configuration, expect disconnect of UE that was active on the aborted link. */
2626 RUA.receive(RUA_Disc_Ind:?);
2627 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
2628
2629 /* Would be nice to test reconnection on the other point-code, too. That would require another cnlink in
2630 * osmo-stp.cfg and module parameters... */
2631
2632 f_sleep(1.0);
2633}
2634testcase TC_apply_sccp() runs on test_CT
2635{
2636 f_init();
2637 f_sleep(1.0);
2638
2639 var ConnHdlr vc_conn;
2640 var template (value) TestHdlrParams pars := t_pars(0);
2641 vc_conn := f_start_handler_with_pars(refers(f_tc_apply_sccp), pars);
2642 vc_conn.done;
2643
2644 f_shutdown_helper();
2645}
2646
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002647/* In the field, we encountered a "normal" RAB Assignment that concludes successfully, followed by another RAB
2648 * Assignment that has different SDU subflow parameters, and does not contain RTP information. At the time of writing,
2649 * it seems that the second RAB Assignment causes a crash. Play through this scenario. */
2650friend function f_tc_second_rab_assignment(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2651 var MgcpCommand mgcp_cmd;
2652 var RANAP_PDU tx;
2653 timer T := 5.0;
2654
2655 f_init_handler(pars);
2656 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
2657
2658 tx := f_build_initial_ue(g_pars);
2659 f_iuh2iu_connect(tx);
2660
2661 f_create_rab(pars.mgcp_pars);
2662
2663 /* Now send a second RAB Assignment with different subflows and omitting transportLayerInformation. (Assuming
2664 * the first RAB Assignment's transportLayerInformation remains in use unchanged.) */
2665 var template RAB_SetupOrModifyList rab_sml;
2666 rab_sml := ts_RAB_SML2(t_RAB_id(23),
2667 ts_RabParams,
2668 user_plane_info := omit,
2669 transport_layer_info := omit);
2670 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
2671 BSSAP.send(tx);
2672 T.start;
2673
2674 /* Expect this secondary RAB Assignment to go through unchanged. */
2675 f_rua_expect(tx);
2676
2677 /* I'm guessing that the RAB Assignment Response also omits transportLayerInformation, so far not known because
2678 * osmo-hnbgw crashed before we could receive the response. */
2679
2680 /* Send back RAB Assignment Response via Iuh */
2681 var template RAB_SetupOrModifiedList rab_smdl;
2682 rab_smdl := ts_RAB_SMdL_no_tla(t_RAB_id(23));
2683 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
2684 RUA.send(tx);
2685 f_bssap_expect(tx);
2686
2687 /* Send Iu Release */
2688 tx := valueof(ts_RANAP_IuReleaseCommand(ts_RanapCause_om_intervention));
2689 f_iu2iuh(tx);
2690
2691 T.start;
2692 alt {
2693 [] as_mgcp_dlcx(pars) {}
2694 [] T.timeout {
2695 setverdict(fail, "Timeout waiting for DLCX");
2696 }
2697 }
2698
2699 tx := valueof(ts_RANAP_IuReleaseComplete());
2700 f_iuh2iu(tx);
2701}
2702
2703testcase TC_second_rab_assignment() runs on test_CT {
2704 var ConnHdlr vc_conn;
2705 g_num_hnbs := 1;
2706 f_init();
2707
2708 vc_conn := f_start_handler_with_pars(refers(f_tc_second_rab_assignment), t_pars(3));
2709 vc_conn.done;
2710
2711 f_shutdown_helper();
2712}
2713
Daniel Willmann19b8d902022-01-05 09:12:34 +01002714control {
2715 execute(TC_hnb_register());
Daniel Willmannc79679a2022-08-23 17:48:39 +02002716 execute(TC_hnb_register_duplicate());
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +02002717 execute(TC_hnb_register_duplicate_reuse_sctp_assoc());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002718 execute(TC_ranap_cs_initial_ue());
2719 execute(TC_ranap_ps_initial_ue());
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02002720 execute(TC_ranap_cs_initial_ue_empty_cr());
2721 execute(TC_ranap_ps_initial_ue_empty_cr());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002722 execute(TC_ranap_cs_bidir());
2723 execute(TC_ranap_ps_bidir());
2724 execute(TC_rab_assignment());
2725 execute(TC_rab_release());
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01002726 execute(TC_rab_assign_fail());
Daniel Willmann37c877f2022-02-22 16:47:06 +01002727 execute(TC_rab_assign_mgcp_to());
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01002728 execute(TC_rab_assign_mgw_iuup_addr_chg());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002729 execute(TC_ranap_cs_mo_disconnect());
2730 execute(TC_ranap_ps_mo_disconnect());
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02002731
2732 if (mp_enable_pfcp_tests) {
2733 execute(TC_ps_rab_assignment_with_pfcp());
2734 } else {
2735 execute(TC_ps_rab_assignment_without_pfcp());
2736 }
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02002737
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002738 execute( TC_mscpool_L3Compl_on_1_cnlink() );
2739 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
2740 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
2741 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
2742 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
2743 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
2744 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
2745 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
2746 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02002747 execute( TC_mscpool_paging_imsi() );
2748 execute( TC_mscpool_paging_tmsi() );
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002749 execute( TC_mscpool_no_allow_attach_round_robin() );
2750 execute( TC_mscpool_no_allow_attach_valid_nri() );
2751 execute( TC_mscpool_sccp_n_pcstate_detaches_cnlink() );
2752 execute( TC_mscpool_sccp_n_pcstate_attaches_cnlink() );
2753
2754 execute( TC_sgsnpool_L3Compl_on_1_cnlink() );
2755 execute( TC_sgsnpool_L3Complete_no_nri_round_robin() );
2756 execute( TC_sgsnpool_L3Complete_valid_nri_1() );
2757 execute( TC_sgsnpool_L3Complete_valid_nri_2() );
2758 execute( TC_sgsnpool_nri_from_other_PLMN() );
2759 execute( TC_sgsnpool_sccp_n_pcstate_detaches_cnlink() );
2760 execute( TC_sgsnpool_sccp_n_pcstate_attaches_cnlink() );
2761
Oliver Smithaa919b42023-11-14 11:30:55 +01002762 /* Run only on nightly since it makes osmo-hnbgw <= 1.5.0 crash: OS#6253 */
2763 if (f_osmo_repo_is("nightly")) {
2764 execute(TC_second_rab_assignment());
2765 }
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002766
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02002767 /* Run at the end since it makes osmo-hnbgw <= 1.3.0 crash: OS#5676 */
2768 execute(TC_hnb_reregister_reuse_sctp_assoc());
Neels Hofmeyrd019cc02023-06-02 16:31:23 +02002769
2770 /* Run at the end since it messes with the SCCP config */
2771 execute( TC_apply_sccp() );
Daniel Willmann19b8d902022-01-05 09:12:34 +01002772}
2773
2774}