Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 1 | module 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 | |
| 13 | import from Misc_Helpers all; |
| 14 | import from General_Types all; |
| 15 | import from Osmocom_Types all; |
| 16 | import from IPL4asp_Types all; |
| 17 | import from Native_Functions all; |
| 18 | |
| 19 | import from SDP_Types all; |
| 20 | |
| 21 | import from StatsD_Checker all; |
| 22 | |
| 23 | import from TELNETasp_PortType all; |
| 24 | import from Osmocom_VTY_Functions all; |
| 25 | |
| 26 | import from HNBAP_Templates all; |
| 27 | |
| 28 | import from Iuh_Emulation all; |
| 29 | |
Pau Espin Pedrol | 32fb54e | 2021-11-29 16:21:26 +0100 | [diff] [blame] | 30 | import from RTP_Types all; |
| 31 | import from RTP_Emulation all; |
| 32 | |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame] | 33 | import from HNBLLIF_CodecPort all; |
| 34 | import from HNBLLIF_Types all; |
| 35 | import from HNBLLIF_Templates all; |
| 36 | |
Pau Espin Pedrol | 9e18372 | 2021-12-02 20:12:25 +0100 | [diff] [blame] | 37 | import from GTP_Emulation all; |
| 38 | import from GTP_Templates all; |
| 39 | import from GTP_CodecPort all; |
| 40 | import from GTPU_Types all; |
| 41 | |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 42 | /* this component represents a single Iuh connection at the HNBGW. */ |
Harald Welte | cb3e2d7 | 2022-01-10 19:14:28 +0100 | [diff] [blame] | 43 | type component HNBGW_ConnHdlr extends Iuh_ConnHdlr, GTP_ConnHdlr, StatsD_ConnHdlr { |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 44 | port TELNETasp_PT HNBVTY; |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame] | 45 | /* HNBLLIF Interface of HNodeB */ |
| 46 | port HNBLLIF_CODEC_PT LLSK; |
| 47 | var integer g_llsk_conn_id; |
| 48 | |
Pau Espin Pedrol | 32fb54e | 2021-11-29 16:21:26 +0100 | [diff] [blame] | 49 | var RTP_Emulation_CT vc_RTPEM; |
| 50 | port RTPEM_CTRL_PT RTPEM_CTRL; |
| 51 | port RTPEM_DATA_PT RTPEM_DATA; |
Pau Espin Pedrol | 9e18372 | 2021-12-02 20:12:25 +0100 | [diff] [blame] | 52 | |
| 53 | var GTP_Emulation_CT vc_GTP; |
| 54 | |
| 55 | |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 56 | var TestHdlrParams g_pars; |
| 57 | |
| 58 | var boolean g_vty_initialized := false; |
| 59 | } |
| 60 | |
| 61 | function 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 Pedrol | 9e18372 | 2021-12-02 20:12:25 +0100 | [diff] [blame] | 70 | private function f_HNBGW_ConnHdlr_init_iuh(charstring id) runs on HNBGW_ConnHdlr { |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 71 | var Iuh_Emulation_CT vc_Iuh; |
Pau Espin Pedrol | 637beab | 2021-12-20 12:45:09 +0100 | [diff] [blame] | 72 | vc_Iuh := Iuh_Emulation_CT.create(id & "-HNBGW") alive; |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 73 | 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 Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame] | 81 | vc_Iuh.start(Iuh_Emulation.main(iuh_pars, id & "-Iuh")); |
Pau Espin Pedrol | 9e18372 | 2021-12-02 20:12:25 +0100 | [diff] [blame] | 82 | } |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 83 | |
Pau Espin Pedrol | 9e18372 | 2021-12-02 20:12:25 +0100 | [diff] [blame] | 84 | private 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 Pedrol | 637beab | 2021-12-20 12:45:09 +0100 | [diff] [blame] | 95 | vc_GTP := GTP_Emulation_CT.create(id) alive; |
Pau Espin Pedrol | 9e18372 | 2021-12-02 20:12:25 +0100 | [diff] [blame] | 96 | 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 */ |
| 102 | function 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 Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 106 | f_HNBGW_ConnHdlr_init_vty(); |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame] | 107 | |
| 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 | |
| 113 | function 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 Pedrol | 32fb54e | 2021-11-29 16:21:26 +0100 | [diff] [blame] | 138 | 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 Pedrol | 9e18372 | 2021-12-02 20:12:25 +0100 | [diff] [blame] | 145 | 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 Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | type record TestHdlrParams { |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame] | 155 | charstring hnbllif_sk_path, /* "" means don't connect */ |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 156 | charstring hnbgw_addr, |
| 157 | charstring hnodeb_addr, |
| 158 | integer hnbgw_port, |
Pau Espin Pedrol | 32fb54e | 2021-11-29 16:21:26 +0100 | [diff] [blame] | 159 | integer hnbgw_rtp_port, |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 160 | uint16_t rnc_id, |
| 161 | charstring hNB_Identity_Info, |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame] | 162 | uint16_t mcc, |
| 163 | uint16_t mnc, |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 164 | 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. */ |
| 172 | template (value) TestHdlrParams t_def_TestHdlrPars := { |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame] | 173 | hnbllif_sk_path := HNBLL_SOCK_DEFAULT, |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 174 | hnbgw_addr := "127.0.0.1", |
| 175 | hnodeb_addr := "127.0.0.1", |
| 176 | hnbgw_port := 29169, |
Pau Espin Pedrol | 32fb54e | 2021-11-29 16:21:26 +0100 | [diff] [blame] | 177 | hnbgw_rtp_port := 9000, |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 178 | rnc_id := 23, |
| 179 | hNB_Identity_Info := "OsmoHNodeB", |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame] | 180 | mcc := 1, |
| 181 | mnc := 1, |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 182 | cell_identity := 1, |
| 183 | lac := 2, |
| 184 | rac := 3, |
| 185 | sac := 4 |
| 186 | } |
| 187 | |
Pau Espin Pedrol | 9e18372 | 2021-12-02 20:12:25 +0100 | [diff] [blame] | 188 | template (value) GtpPeer ts_GtpPeerU(charstring ip) := { |
| 189 | connId := 1, |
| 190 | remName := ip, |
| 191 | remPort := GTP1U_PORT |
| 192 | } |
| 193 | |
| 194 | function 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 Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame] | 199 | /* HNBLLIF socket may at any time receive a new INFO.ind */ |
| 200 | altstep 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 | |
| 213 | function f_llsk_rx(template (present) HNBLLIF_Message exp_tmpl) runs on HNBGW_ConnHdlr |
| 214 | return template (present) HNBLLIF_send_data { |
| 215 | return t_SD_HNBLLIF(g_llsk_conn_id, exp_tmpl); |
| 216 | } |
| 217 | |
| 218 | function f_llsk_tx(template (value) HNBLLIF_Message tx_msg) runs on HNBGW_ConnHdlr |
| 219 | return template (value) HNBLLIF_send_data { |
| 220 | return ts_SD_HNBLLIF(g_llsk_conn_id, tx_msg); |
| 221 | } |
| 222 | |
| 223 | function 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 Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 235 | |
| 236 | function f_handle_hnbap_hnb_register_req() |
| 237 | runs on HNBGW_ConnHdlr { |
| 238 | HNBAP.receive(tr_HNBAP_HNBRegisterRequest(char2oct(g_pars.hNB_Identity_Info), |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame] | 239 | f_enc_mcc_mnc(g_pars.mcc, g_pars.mnc), |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 240 | 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 Pedrol | 32fb54e | 2021-11-29 16:21:26 +0100 | [diff] [blame] | 248 | /* Initialize and start the RTP emulation component for a ConnHdlr */ |
Pau Espin Pedrol | 58a69df | 2021-12-21 14:48:23 +0100 | [diff] [blame] | 249 | function f_HNBGW_rtpem_activate(inout octetstring payload) |
Pau Espin Pedrol | 32fb54e | 2021-11-29 16:21:26 +0100 | [diff] [blame] | 250 | runs on HNBGW_ConnHdlr { |
Pau Espin Pedrol | 58a69df | 2021-12-21 14:48:23 +0100 | [diff] [blame] | 251 | /* Initialize, connect and start the emulation component */ |
| 252 | var RtpemConfig cfg := c_RtpemDefaultCfg; |
| 253 | cfg.iuup_mode := true; |
Pau Espin Pedrol | 6ed7630 | 2022-05-25 18:09:37 +0200 | [diff] [blame] | 254 | cfg.iuup_cfg.active_init := false; |
Pau Espin Pedrol | 58a69df | 2021-12-21 14:48:23 +0100 | [diff] [blame] | 255 | cfg.tx_payload_type := 96; |
| 256 | |
Pau Espin Pedrol | 637beab | 2021-12-20 12:45:09 +0100 | [diff] [blame] | 257 | vc_RTPEM := RTP_Emulation_CT.create(testcasename() & "-RTPEM") alive; |
Pau Espin Pedrol | 32fb54e | 2021-11-29 16:21:26 +0100 | [diff] [blame] | 258 | 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 Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 263 | |
Pau Espin Pedrol | 32fb54e | 2021-11-29 16:21:26 +0100 | [diff] [blame] | 264 | /* 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 Pedrol | 32fb54e | 2021-11-29 16:21:26 +0100 | [diff] [blame] | 276 | /* Set the given RTP emulation mode */ |
Pau Espin Pedrol | 58a69df | 2021-12-21 14:48:23 +0100 | [diff] [blame] | 277 | f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_RXONLY); |
| 278 | } |
| 279 | |
| 280 | function f_HNBGW_rtpem_connect(HostName remote_host, PortNumber remote_port) |
| 281 | runs 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 Pedrol | 32fb54e | 2021-11-29 16:21:26 +0100 | [diff] [blame] | 285 | } |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 286 | |
| 287 | } |