blob: 6b064378aef8d9b5f4a9024f84c7faf8d65661cd [file] [log] [blame]
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +01001module HNBGW_ConnectionHandler {
2
3/* HNBGW Connection Handler of HNB_Tests in TTCN-3
4 * (C) 2021 by sysmocom - s.m.f.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
13import from Misc_Helpers all;
14import from General_Types all;
15import from Osmocom_Types all;
16import from IPL4asp_Types all;
17import from Native_Functions all;
18
19import from SDP_Types all;
20
21import from StatsD_Checker all;
22
23import from TELNETasp_PortType all;
24import from Osmocom_VTY_Functions all;
25
26import from HNBAP_Templates all;
27
28import from Iuh_Emulation all;
29
Pau Espin Pedrol32fb54e2021-11-29 16:21:26 +010030import from RTP_Types all;
31import from RTP_Emulation all;
32
Pau Espin Pedrola6bbb8c2021-11-24 17:00:03 +010033import from HNBLLIF_CodecPort all;
34import from HNBLLIF_Types all;
35import from HNBLLIF_Templates all;
36
Pau Espin Pedrol9e183722021-12-02 20:12:25 +010037import from GTP_Emulation all;
38import from GTP_Templates all;
39import from GTP_CodecPort all;
40import from GTPU_Types all;
41
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +010042/* this component represents a single Iuh connection at the HNBGW. */
Harald Weltecb3e2d72022-01-10 19:14:28 +010043type component HNBGW_ConnHdlr extends Iuh_ConnHdlr, GTP_ConnHdlr, StatsD_ConnHdlr {
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +010044 port TELNETasp_PT HNBVTY;
Pau Espin Pedrola6bbb8c2021-11-24 17:00:03 +010045 /* HNBLLIF Interface of HNodeB */
46 port HNBLLIF_CODEC_PT LLSK;
47 var integer g_llsk_conn_id;
48
Pau Espin Pedrol32fb54e2021-11-29 16:21:26 +010049 var RTP_Emulation_CT vc_RTPEM;
50 port RTPEM_CTRL_PT RTPEM_CTRL;
51 port RTPEM_DATA_PT RTPEM_DATA;
Pau Espin Pedrol9e183722021-12-02 20:12:25 +010052
53 var GTP_Emulation_CT vc_GTP;
54
55
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +010056 var TestHdlrParams g_pars;
57
58 var boolean g_vty_initialized := false;
59}
60
61function f_HNBGW_ConnHdlr_init_vty() runs on HNBGW_ConnHdlr {
62 if (not g_vty_initialized) {
63 map(self:HNBVTY, system:HNBVTY);
64 f_vty_set_prompts(HNBVTY);
65 f_vty_transceive(HNBVTY, "enable");
66 g_vty_initialized := true;
67 }
68}
69
Pau Espin Pedrol9e183722021-12-02 20:12:25 +010070private function f_HNBGW_ConnHdlr_init_iuh(charstring id) runs on HNBGW_ConnHdlr {
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +010071 var Iuh_Emulation_CT vc_Iuh;
Pau Espin Pedrol637beab2021-12-20 12:45:09 +010072 vc_Iuh := Iuh_Emulation_CT.create(id & "-HNBGW") alive;
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +010073 connect(self:HNBAP, vc_Iuh:HNBAP);
74 connect(self:RUA, vc_Iuh:RUA);
75
76 var Iuh_conn_parameters iuh_pars;
77 iuh_pars.remote_ip := g_pars.hnodeb_addr;
78 iuh_pars.remote_sctp_port := -1;
79 iuh_pars.local_ip := g_pars.hnbgw_addr;
80 iuh_pars.local_sctp_port := g_pars.hnbgw_port;
Pau Espin Pedrola6bbb8c2021-11-24 17:00:03 +010081 vc_Iuh.start(Iuh_Emulation.main(iuh_pars, id & "-Iuh"));
Pau Espin Pedrol9e183722021-12-02 20:12:25 +010082}
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +010083
Pau Espin Pedrol9e183722021-12-02 20:12:25 +010084private function f_HNBGW_ConnHdlr_init_gtp(charstring id) runs on HNBGW_ConnHdlr {
85 id := id & "-GTP";
86
87 var GtpEmulationCfg gtp_cfg := {
88 gtpc_bind_ip := g_pars.hnbgw_addr,
89 gtpc_bind_port := GTP1C_PORT,
90 gtpu_bind_ip := g_pars.hnbgw_addr,
91 gtpu_bind_port := GTP1U_PORT,
92 sgsn_role := false
93 };
94
Pau Espin Pedrol637beab2021-12-20 12:45:09 +010095 vc_GTP := GTP_Emulation_CT.create(id) alive;
Pau Espin Pedrol9e183722021-12-02 20:12:25 +010096 connect(self:GTP, vc_GTP:CLIENT);
97 connect(self:GTP_PROC, vc_GTP:CLIENT_PROC);
98 vc_GTP.start(GTP_Emulation.main(gtp_cfg));
99}
100
101/* initialize all parameters */
102function f_HNBGW_ConnHdlr_init(charstring id, TestHdlrParams pars) runs on HNBGW_ConnHdlr {
103 g_pars := valueof(pars);
104 f_HNBGW_ConnHdlr_init_iuh(id);
105 f_HNBGW_ConnHdlr_init_gtp(id);
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +0100106 f_HNBGW_ConnHdlr_init_vty();
Pau Espin Pedrola6bbb8c2021-11-24 17:00:03 +0100107
108 /* Connect to HNB on LLSK and do HELLO ping-pong */
109 f_start_hnbllif(LLSK, id & "-LLSK", g_pars.hnbllif_sk_path, g_llsk_conn_id);
110}
111
112
113function f_start_hnbllif(HNBLLIF_CODEC_PT pt, charstring id, charstring hnbllif_sk_path, out integer hnbllif_conn_id) {
114 timer T := 2.0;
115 var HNBLLIF_send_data sd;
116 var HNBLLIF_Message last_hello_cnf;
117 if (hnbllif_sk_path == "") {
118 hnbllif_conn_id := -1;
119 return;
120 }
121 hnbllif_conn_id := f_hnbllif_connect(pt, hnbllif_sk_path);
122
123 T.start;
124 pt.send(t_SD_HNBLLIF(hnbllif_conn_id, ts_HNBLLIF_CTL_HELLO_REQ(HNBLL_IF_SAPI_CTL, HNBLLIF_Types.mp_hnbllif_version)));
125 alt {
126 [] as_hnbllif_hello_cnf(pt, hnbllif_conn_id, last_hello_cnf, HNBLL_IF_SAPI_CTL, HNBLLIF_Types.mp_hnbllif_version);
127 [] T.timeout {
128 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for HNBLLIF HELLO.REQ SAPI=CTL");
129 }
130 }
131 pt.send(t_SD_HNBLLIF(hnbllif_conn_id, ts_HNBLLIF_CTL_HELLO_REQ(HNBLL_IF_SAPI_IUH, 0)));
132 alt {
133 [] as_hnbllif_hello_cnf(pt, hnbllif_conn_id, last_hello_cnf, HNBLL_IF_SAPI_IUH, 0);
134 [] T.timeout {
135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for HNBLLIF HELLO.REQ SAPI=IUH");
136 }
137 }
Pau Espin Pedrol32fb54e2021-11-29 16:21:26 +0100138 pt.send(t_SD_HNBLLIF(hnbllif_conn_id, ts_HNBLLIF_CTL_HELLO_REQ(HNBLL_IF_SAPI_AUDIO, 0)));
139 alt {
140 [] as_hnbllif_hello_cnf(pt, hnbllif_conn_id, last_hello_cnf, HNBLL_IF_SAPI_AUDIO, 0);
141 [] T.timeout {
142 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for HNBLLIF HELLO.REQ SAPI=AUDIO");
143 }
144 }
Pau Espin Pedrol9e183722021-12-02 20:12:25 +0100145 pt.send(t_SD_HNBLLIF(hnbllif_conn_id, ts_HNBLLIF_CTL_HELLO_REQ(HNBLL_IF_SAPI_GTP, 0)));
146 alt {
147 [] as_hnbllif_hello_cnf(pt, hnbllif_conn_id, last_hello_cnf, HNBLL_IF_SAPI_GTP, 0);
148 [] T.timeout {
149 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for HNBLLIF HELLO.REQ SAPI=GTP");
150 }
151 }
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +0100152}
153
154type record TestHdlrParams {
Pau Espin Pedrola6bbb8c2021-11-24 17:00:03 +0100155 charstring hnbllif_sk_path, /* "" means don't connect */
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +0100156 charstring hnbgw_addr,
157 charstring hnodeb_addr,
158 integer hnbgw_port,
Pau Espin Pedrol32fb54e2021-11-29 16:21:26 +0100159 integer hnbgw_rtp_port,
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +0100160 uint16_t rnc_id,
161 charstring hNB_Identity_Info,
Pau Espin Pedrola6bbb8c2021-11-24 17:00:03 +0100162 uint16_t mcc,
163 uint16_t mnc,
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +0100164 uint32_t cell_identity,
165 uint16_t lac,
166 uint8_t rac,
167 uint8_t sac
168};
169
170/* Note: Do not use valueof() to get a value of this template, use
171 * f_gen_test_hdlr_pars() instead in order to get a configuration. */
172template (value) TestHdlrParams t_def_TestHdlrPars := {
Pau Espin Pedrola6bbb8c2021-11-24 17:00:03 +0100173 hnbllif_sk_path := HNBLL_SOCK_DEFAULT,
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +0100174 hnbgw_addr := "127.0.0.1",
175 hnodeb_addr := "127.0.0.1",
176 hnbgw_port := 29169,
Pau Espin Pedrol32fb54e2021-11-29 16:21:26 +0100177 hnbgw_rtp_port := 9000,
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +0100178 rnc_id := 23,
179 hNB_Identity_Info := "OsmoHNodeB",
Pau Espin Pedrola6bbb8c2021-11-24 17:00:03 +0100180 mcc := 1,
181 mnc := 1,
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +0100182 cell_identity := 1,
183 lac := 2,
184 rac := 3,
185 sac := 4
186}
187
Pau Espin Pedrol9e183722021-12-02 20:12:25 +0100188template (value) GtpPeer ts_GtpPeerU(charstring ip) := {
189 connId := 1,
190 remName := ip,
191 remPort := GTP1U_PORT
192}
193
194function f_gtpu_send(uint32_t tei, octetstring payload) runs on HNBGW_ConnHdlr {
195 var GtpPeer peer := valueof(ts_GtpPeerU(g_pars.hnodeb_addr));
196 GTP.send(ts_GTP1U_GPDU(peer, 0 /*seq*/, int2oct(tei, 4), payload));
197}
198
Pau Espin Pedrola6bbb8c2021-11-24 17:00:03 +0100199/* HNBLLIF socket may at any time receive a new INFO.ind */
200altstep as_hnbllif_hello_cnf(HNBLLIF_CODEC_PT pt, integer hnbllif_conn_id,
201 out HNBLLIF_Message last_hello_cnf,
202 template (present) HNBLLIF_Sapi exp_sapi := ?,
203 template (present) uint16_t exp_version := ?) {
204 var HNBLLIF_send_data sd;
205 [] pt.receive(t_SD_HNBLLIF(hnbllif_conn_id, tr_HNBLLIF_CTL_HELLO_CNF(exp_sapi, exp_version))) -> value sd {
206 last_hello_cnf := sd.data;
207 }
208 [] pt.receive(t_SD_HNBLLIF(hnbllif_conn_id, tr_HNBLLIF_CTL_HELLO_CNF(?))) -> value sd {
209 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid API_VERSION received");
210 }
211}
212
213function f_llsk_rx(template (present) HNBLLIF_Message exp_tmpl) runs on HNBGW_ConnHdlr
214return template (present) HNBLLIF_send_data {
215 return t_SD_HNBLLIF(g_llsk_conn_id, exp_tmpl);
216}
217
218function f_llsk_tx(template (value) HNBLLIF_Message tx_msg) runs on HNBGW_ConnHdlr
219return template (value) HNBLLIF_send_data {
220 return ts_SD_HNBLLIF(g_llsk_conn_id, tx_msg);
221}
222
223function f_enc_mcc_mnc(uint16_t mcc_uint, uint16_t mnc_uint) return OCT3 {
224 var hexstring mnc;
225 var hexstring mcc := int2hex(mcc_uint, 3);
226
227 if (mnc_uint < 100) {
228 mnc := int2hex(mnc_uint, 2);
229 return hex2oct(mcc[1] & mcc[0] & 'F'H & mcc[2] & mnc[1] & mnc[0]);
230 } else {
231 mnc := int2hex(mnc_uint, 3);
232 return hex2oct(mcc[1] & mcc[0] & mnc[2] & mcc[2] & mnc[1] & mnc[0]);
233 }
234}
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +0100235
236function f_handle_hnbap_hnb_register_req()
237runs on HNBGW_ConnHdlr {
238 HNBAP.receive(tr_HNBAP_HNBRegisterRequest(char2oct(g_pars.hNB_Identity_Info),
Pau Espin Pedrola6bbb8c2021-11-24 17:00:03 +0100239 f_enc_mcc_mnc(g_pars.mcc, g_pars.mnc),
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +0100240 int2bit(g_pars.cell_identity, 28),
241 int2oct(g_pars.lac, 2),
242 int2oct(g_pars.rac, 1),
243 int2oct(g_pars.sac, 2)
244 ));
245 HNBAP.send(ts_HNBAP_HNBRegisterAccept(g_pars.rnc_id));
246}
247
Pau Espin Pedrol32fb54e2021-11-29 16:21:26 +0100248/* Initialize and start the RTP emulation component for a ConnHdlr */
Pau Espin Pedrol58a69df2021-12-21 14:48:23 +0100249function f_HNBGW_rtpem_activate(inout octetstring payload)
Pau Espin Pedrol32fb54e2021-11-29 16:21:26 +0100250runs on HNBGW_ConnHdlr {
Pau Espin Pedrol58a69df2021-12-21 14:48:23 +0100251 /* Initialize, connect and start the emulation component */
252 var RtpemConfig cfg := c_RtpemDefaultCfg;
253 cfg.iuup_mode := true;
Pau Espin Pedrol6ed76302022-05-25 18:09:37 +0200254 cfg.iuup_cfg.active_init := false;
Pau Espin Pedrol58a69df2021-12-21 14:48:23 +0100255 cfg.tx_payload_type := 96;
256
Pau Espin Pedrol637beab2021-12-20 12:45:09 +0100257 vc_RTPEM := RTP_Emulation_CT.create(testcasename() & "-RTPEM") alive;
Pau Espin Pedrol32fb54e2021-11-29 16:21:26 +0100258 map(vc_RTPEM:RTP, system:RTP);
259 map(vc_RTPEM:RTCP, system:RTCP);
260 connect(vc_RTPEM:CTRL, self:RTPEM_CTRL);
261 connect(vc_RTPEM:DATA, self:RTPEM_DATA);
262 vc_RTPEM.start(RTP_Emulation.f_main());
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +0100263
Pau Espin Pedrol32fb54e2021-11-29 16:21:26 +0100264 /* Configure the RTP parameters (TCH/FS). TODO: IuUP */
265 var integer payload_len := 33;
266 var octetstring hdr := 'D0'O;
267
268 /* Pad the payload to conform the expected length */
269 payload := f_pad_oct(hdr & payload, payload_len, '00'O);
270 cfg.tx_fixed_payload := payload;
271 f_rtpem_configure(RTPEM_CTRL, cfg);
272
273 /* Bind the RTP emulation to the configured address */
274 f_rtpem_bind(RTPEM_CTRL, g_pars.hnbgw_addr, g_pars.hnbgw_rtp_port);
275
Pau Espin Pedrol32fb54e2021-11-29 16:21:26 +0100276 /* Set the given RTP emulation mode */
Pau Espin Pedrol58a69df2021-12-21 14:48:23 +0100277 f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_RXONLY);
278}
279
280function f_HNBGW_rtpem_connect(HostName remote_host, PortNumber remote_port)
281runs on HNBGW_ConnHdlr {
282 f_rtpem_connect(RTPEM_CTRL, remote_host, remote_port);
283 /* Set the given RTP emulation mode */
284 f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_BIDIR);
Pau Espin Pedrol32fb54e2021-11-29 16:21:26 +0100285}
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +0100286
287}