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 | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame^] | 30 | import from HNBLLIF_CodecPort all; |
| 31 | import from HNBLLIF_Types all; |
| 32 | import from HNBLLIF_Templates all; |
| 33 | |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 34 | /* this component represents a single Iuh connection at the HNBGW. */ |
| 35 | type component HNBGW_ConnHdlr extends StatsD_ConnHdlr { |
| 36 | port TELNETasp_PT HNBVTY; |
| 37 | port HNBAP_PT HNBAP; |
| 38 | port RUA_PT RUA; |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame^] | 39 | /* HNBLLIF Interface of HNodeB */ |
| 40 | port HNBLLIF_CODEC_PT LLSK; |
| 41 | var integer g_llsk_conn_id; |
| 42 | |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 43 | var TestHdlrParams g_pars; |
| 44 | |
| 45 | var boolean g_vty_initialized := false; |
| 46 | } |
| 47 | |
| 48 | function f_HNBGW_ConnHdlr_init_vty() runs on HNBGW_ConnHdlr { |
| 49 | if (not g_vty_initialized) { |
| 50 | map(self:HNBVTY, system:HNBVTY); |
| 51 | f_vty_set_prompts(HNBVTY); |
| 52 | f_vty_transceive(HNBVTY, "enable"); |
| 53 | g_vty_initialized := true; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /* initialize all parameters */ |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame^] | 58 | function f_HNBGW_ConnHdlr_init(charstring id, TestHdlrParams pars) runs on HNBGW_ConnHdlr { |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 59 | var Iuh_Emulation_CT vc_Iuh; |
| 60 | |
| 61 | g_pars := valueof(pars); |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame^] | 62 | vc_Iuh := Iuh_Emulation_CT.create(id & "-HNBGW"); |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 63 | connect(self:HNBAP, vc_Iuh:HNBAP); |
| 64 | connect(self:RUA, vc_Iuh:RUA); |
| 65 | |
| 66 | var Iuh_conn_parameters iuh_pars; |
| 67 | iuh_pars.remote_ip := g_pars.hnodeb_addr; |
| 68 | iuh_pars.remote_sctp_port := -1; |
| 69 | iuh_pars.local_ip := g_pars.hnbgw_addr; |
| 70 | iuh_pars.local_sctp_port := g_pars.hnbgw_port; |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame^] | 71 | vc_Iuh.start(Iuh_Emulation.main(iuh_pars, id & "-Iuh")); |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 72 | |
| 73 | f_HNBGW_ConnHdlr_init_vty(); |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame^] | 74 | |
| 75 | /* Connect to HNB on LLSK and do HELLO ping-pong */ |
| 76 | f_start_hnbllif(LLSK, id & "-LLSK", g_pars.hnbllif_sk_path, g_llsk_conn_id); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | function f_start_hnbllif(HNBLLIF_CODEC_PT pt, charstring id, charstring hnbllif_sk_path, out integer hnbllif_conn_id) { |
| 81 | timer T := 2.0; |
| 82 | var HNBLLIF_send_data sd; |
| 83 | var HNBLLIF_Message last_hello_cnf; |
| 84 | if (hnbllif_sk_path == "") { |
| 85 | hnbllif_conn_id := -1; |
| 86 | return; |
| 87 | } |
| 88 | hnbllif_conn_id := f_hnbllif_connect(pt, hnbllif_sk_path); |
| 89 | |
| 90 | T.start; |
| 91 | pt.send(t_SD_HNBLLIF(hnbllif_conn_id, ts_HNBLLIF_CTL_HELLO_REQ(HNBLL_IF_SAPI_CTL, HNBLLIF_Types.mp_hnbllif_version))); |
| 92 | alt { |
| 93 | [] as_hnbllif_hello_cnf(pt, hnbllif_conn_id, last_hello_cnf, HNBLL_IF_SAPI_CTL, HNBLLIF_Types.mp_hnbllif_version); |
| 94 | [] T.timeout { |
| 95 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for HNBLLIF HELLO.REQ SAPI=CTL"); |
| 96 | } |
| 97 | } |
| 98 | pt.send(t_SD_HNBLLIF(hnbllif_conn_id, ts_HNBLLIF_CTL_HELLO_REQ(HNBLL_IF_SAPI_IUH, 0))); |
| 99 | alt { |
| 100 | [] as_hnbllif_hello_cnf(pt, hnbllif_conn_id, last_hello_cnf, HNBLL_IF_SAPI_IUH, 0); |
| 101 | [] T.timeout { |
| 102 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for HNBLLIF HELLO.REQ SAPI=IUH"); |
| 103 | } |
| 104 | } |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | type record TestHdlrParams { |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame^] | 108 | charstring hnbllif_sk_path, /* "" means don't connect */ |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 109 | charstring hnbgw_addr, |
| 110 | charstring hnodeb_addr, |
| 111 | integer hnbgw_port, |
| 112 | uint16_t rnc_id, |
| 113 | charstring hNB_Identity_Info, |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame^] | 114 | uint16_t mcc, |
| 115 | uint16_t mnc, |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 116 | uint32_t cell_identity, |
| 117 | uint16_t lac, |
| 118 | uint8_t rac, |
| 119 | uint8_t sac |
| 120 | }; |
| 121 | |
| 122 | /* Note: Do not use valueof() to get a value of this template, use |
| 123 | * f_gen_test_hdlr_pars() instead in order to get a configuration. */ |
| 124 | template (value) TestHdlrParams t_def_TestHdlrPars := { |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame^] | 125 | hnbllif_sk_path := HNBLL_SOCK_DEFAULT, |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 126 | hnbgw_addr := "127.0.0.1", |
| 127 | hnodeb_addr := "127.0.0.1", |
| 128 | hnbgw_port := 29169, |
| 129 | rnc_id := 23, |
| 130 | hNB_Identity_Info := "OsmoHNodeB", |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame^] | 131 | mcc := 1, |
| 132 | mnc := 1, |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 133 | cell_identity := 1, |
| 134 | lac := 2, |
| 135 | rac := 3, |
| 136 | sac := 4 |
| 137 | } |
| 138 | |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame^] | 139 | /* HNBLLIF socket may at any time receive a new INFO.ind */ |
| 140 | altstep as_hnbllif_hello_cnf(HNBLLIF_CODEC_PT pt, integer hnbllif_conn_id, |
| 141 | out HNBLLIF_Message last_hello_cnf, |
| 142 | template (present) HNBLLIF_Sapi exp_sapi := ?, |
| 143 | template (present) uint16_t exp_version := ?) { |
| 144 | var HNBLLIF_send_data sd; |
| 145 | [] pt.receive(t_SD_HNBLLIF(hnbllif_conn_id, tr_HNBLLIF_CTL_HELLO_CNF(exp_sapi, exp_version))) -> value sd { |
| 146 | last_hello_cnf := sd.data; |
| 147 | } |
| 148 | [] pt.receive(t_SD_HNBLLIF(hnbllif_conn_id, tr_HNBLLIF_CTL_HELLO_CNF(?))) -> value sd { |
| 149 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid API_VERSION received"); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | function f_llsk_rx(template (present) HNBLLIF_Message exp_tmpl) runs on HNBGW_ConnHdlr |
| 154 | return template (present) HNBLLIF_send_data { |
| 155 | return t_SD_HNBLLIF(g_llsk_conn_id, exp_tmpl); |
| 156 | } |
| 157 | |
| 158 | function f_llsk_tx(template (value) HNBLLIF_Message tx_msg) runs on HNBGW_ConnHdlr |
| 159 | return template (value) HNBLLIF_send_data { |
| 160 | return ts_SD_HNBLLIF(g_llsk_conn_id, tx_msg); |
| 161 | } |
| 162 | |
| 163 | function f_enc_mcc_mnc(uint16_t mcc_uint, uint16_t mnc_uint) return OCT3 { |
| 164 | var hexstring mnc; |
| 165 | var hexstring mcc := int2hex(mcc_uint, 3); |
| 166 | |
| 167 | if (mnc_uint < 100) { |
| 168 | mnc := int2hex(mnc_uint, 2); |
| 169 | return hex2oct(mcc[1] & mcc[0] & 'F'H & mcc[2] & mnc[1] & mnc[0]); |
| 170 | } else { |
| 171 | mnc := int2hex(mnc_uint, 3); |
| 172 | return hex2oct(mcc[1] & mcc[0] & mnc[2] & mcc[2] & mnc[1] & mnc[0]); |
| 173 | } |
| 174 | } |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 175 | |
| 176 | function f_handle_hnbap_hnb_register_req() |
| 177 | runs on HNBGW_ConnHdlr { |
| 178 | HNBAP.receive(tr_HNBAP_HNBRegisterRequest(char2oct(g_pars.hNB_Identity_Info), |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame^] | 179 | f_enc_mcc_mnc(g_pars.mcc, g_pars.mnc), |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 180 | int2bit(g_pars.cell_identity, 28), |
| 181 | int2oct(g_pars.lac, 2), |
| 182 | int2oct(g_pars.rac, 1), |
| 183 | int2oct(g_pars.sac, 2) |
| 184 | )); |
| 185 | HNBAP.send(ts_HNBAP_HNBRegisterAccept(g_pars.rnc_id)); |
| 186 | } |
| 187 | |
| 188 | |
| 189 | |
| 190 | } |