blob: da220c1f428f293219244abd16eaf064af72a672 [file] [log] [blame]
Philippb4cb8382016-09-29 17:01:57 +02001/* Test OML attribute generator */
2
3/* (C) 2016 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
4 * All Rights Reserved
5 *
6 * Author: Philipp Maier
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
Neels Hofmeyrc0164792017-09-04 15:15:32 +020022#include <osmocom/bsc/debug.h>
23#include <osmocom/bsc/gsm_data.h>
24#include <osmocom/bsc/bts_ipaccess_nanobts_omlattr.h>
Pau Espin Pedrol388ed582020-07-15 20:53:16 +020025#include <osmocom/bsc/bts.h>
Philippb4cb8382016-09-29 17:01:57 +020026
27#include <osmocom/core/talloc.h>
28#include <osmocom/core/utils.h>
29#include <osmocom/core/application.h>
Alexander Couzens2f9df962020-09-21 18:35:24 +020030#include <osmocom/core/sockaddr_str.h>
Philippb4cb8382016-09-29 17:01:57 +020031
32#include <stdio.h>
33#include <string.h>
34
35struct gsm_bts_model bts_model_nanobts = {
36 .type = GSM_BTS_TYPE_NANOBTS,
37 .name = "nanobts",
38 .start = NULL,
39 .oml_rcvmsg = NULL,
40 .e1line_bind_ops = NULL,
41 .nm_att_tlvdef = {
42 .def = {
43 /* ip.access specifics */
44 [NM_ATT_IPACC_DST_IP] = {TLV_TYPE_FIXED, 4},
45 [NM_ATT_IPACC_DST_IP_PORT] =
46 {TLV_TYPE_FIXED, 2},
47 [NM_ATT_IPACC_STREAM_ID] = {TLV_TYPE_TV,},
48 [NM_ATT_IPACC_SEC_OML_CFG] =
49 {TLV_TYPE_FIXED, 6},
50 [NM_ATT_IPACC_IP_IF_CFG] =
51 {TLV_TYPE_FIXED, 8},
52 [NM_ATT_IPACC_IP_GW_CFG] =
53 {TLV_TYPE_FIXED, 12},
54 [NM_ATT_IPACC_IN_SERV_TIME] =
55 {TLV_TYPE_FIXED, 4},
56 [NM_ATT_IPACC_LOCATION] = {TLV_TYPE_TL16V},
57 [NM_ATT_IPACC_PAGING_CFG] =
58 {TLV_TYPE_FIXED, 2},
59 [NM_ATT_IPACC_UNIT_ID] = {TLV_TYPE_TL16V},
60 [NM_ATT_IPACC_UNIT_NAME] = {TLV_TYPE_TL16V},
61 [NM_ATT_IPACC_SNMP_CFG] = {TLV_TYPE_TL16V},
62 [NM_ATT_IPACC_PRIM_OML_CFG_LIST] =
63 {TLV_TYPE_TL16V},
64 [NM_ATT_IPACC_NV_FLAGS] = {TLV_TYPE_TL16V},
65 [NM_ATT_IPACC_FREQ_CTRL] =
66 {TLV_TYPE_FIXED, 2},
67 [NM_ATT_IPACC_PRIM_OML_FB_TOUT] =
68 {TLV_TYPE_TL16V},
69 [NM_ATT_IPACC_CUR_SW_CFG] = {TLV_TYPE_TL16V},
70 [NM_ATT_IPACC_TIMING_BUS] = {TLV_TYPE_TL16V},
71 [NM_ATT_IPACC_CGI] = {TLV_TYPE_TL16V},
72 [NM_ATT_IPACC_RAC] = {TLV_TYPE_TL16V},
73 [NM_ATT_IPACC_OBJ_VERSION] = {TLV_TYPE_TL16V},
74 [NM_ATT_IPACC_GPRS_PAGING_CFG] =
75 {TLV_TYPE_TL16V},
76 [NM_ATT_IPACC_NSEI] = {TLV_TYPE_TL16V},
77 [NM_ATT_IPACC_BVCI] = {TLV_TYPE_TL16V},
78 [NM_ATT_IPACC_NSVCI] = {TLV_TYPE_TL16V},
79 [NM_ATT_IPACC_NS_CFG] = {TLV_TYPE_TL16V},
80 [NM_ATT_IPACC_BSSGP_CFG] = {TLV_TYPE_TL16V},
81 [NM_ATT_IPACC_NS_LINK_CFG] = {TLV_TYPE_TL16V},
82 [NM_ATT_IPACC_RLC_CFG] = {TLV_TYPE_TL16V},
83 [NM_ATT_IPACC_ALM_THRESH_LIST] =
84 {TLV_TYPE_TL16V},
85 [NM_ATT_IPACC_MONIT_VAL_LIST] =
86 {TLV_TYPE_TL16V},
87 [NM_ATT_IPACC_TIB_CONTROL] = {TLV_TYPE_TL16V},
88 [NM_ATT_IPACC_SUPP_FEATURES] =
89 {TLV_TYPE_TL16V},
90 [NM_ATT_IPACC_CODING_SCHEMES] =
91 {TLV_TYPE_TL16V},
92 [NM_ATT_IPACC_RLC_CFG_2] = {TLV_TYPE_TL16V},
93 [NM_ATT_IPACC_HEARTB_TOUT] = {TLV_TYPE_TL16V},
94 [NM_ATT_IPACC_UPTIME] = {TLV_TYPE_TL16V},
95 [NM_ATT_IPACC_RLC_CFG_3] = {TLV_TYPE_TL16V},
96 [NM_ATT_IPACC_SSL_CFG] = {TLV_TYPE_TL16V},
97 [NM_ATT_IPACC_SEC_POSSIBLE] =
98 {TLV_TYPE_TL16V},
99 [NM_ATT_IPACC_IML_SSL_STATE] =
100 {TLV_TYPE_TL16V},
101 [NM_ATT_IPACC_REVOC_DATE] = {TLV_TYPE_TL16V},
102 },
103 },
104};
105
106static void test_nanobts_attr_bts_get(struct gsm_bts *bts, uint8_t *expected)
107{
108 struct msgb *msgb;
109
110 printf("Testing nanobts_attr_bts_get()...\n");
111
112 msgb = nanobts_attr_bts_get(bts);
113 printf("result= %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
114 printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
115 OSMO_ASSERT(memcmp(msgb->data, expected, msgb->len) == 0);
116 msgb_free(msgb);
117
118 printf("ok.\n");
119 printf("\n");
120}
121
122static void test_nanobts_attr_nse_get(struct gsm_bts *bts, uint8_t *expected)
123{
124 struct msgb *msgb;
125
126 printf("Testing nanobts_attr_nse_get()...\n");
127
128 msgb = nanobts_attr_nse_get(bts);
129 printf("result= %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
130 printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
131 OSMO_ASSERT(memcmp(msgb->data, expected, msgb->len) == 0);
132 msgb_free(msgb);
133
134 printf("ok.\n");
135 printf("\n");
136}
137
138static void test_nanobts_attr_cell_get(struct gsm_bts *bts, uint8_t *expected)
139{
140 struct msgb *msgb;
141
142 printf("Testing nanobts_attr_cell_get()...\n");
143
144 msgb = nanobts_attr_cell_get(bts);
145 printf("result= %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
146 printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
147 OSMO_ASSERT(memcmp(msgb->data, expected, msgb->len) == 0);
148 msgb_free(msgb);
149
150 printf("ok.\n");
151 printf("\n");
152}
153
154static void test_nanobts_attr_nscv_get(struct gsm_bts *bts, uint8_t *expected)
155{
156 struct msgb *msgb;
157
158 printf("Testing nanobts_attr_nscv_get()...\n");
159
160 msgb = nanobts_attr_nscv_get(bts);
161 printf("result= %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
162 printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
163 OSMO_ASSERT(memcmp(msgb->data, expected, msgb->len) == 0);
164 msgb_free(msgb);
165
166 printf("ok.\n");
167 printf("\n");
168}
169
170static void test_nanobts_attr_radio_get(struct gsm_bts *bts,
171 struct gsm_bts_trx *trx,
172 uint8_t *expected)
173{
174 struct msgb *msgb;
175
176 printf("Testing nanobts_attr_nscv_get()...\n");
177
178 msgb = nanobts_attr_radio_get(bts, trx);
179 printf("result= %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
180 printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
181 OSMO_ASSERT(memcmp(msgb->data, expected, msgb->len) == 0);
182 msgb_free(msgb);
183
184 printf("ok.\n");
185 printf("\n");
186}
187
Neels Hofmeyr7997bf42018-02-13 17:16:44 +0100188static const struct log_info_cat log_categories[] = {
189};
190
191static const struct log_info log_info = {
192 .cat = log_categories,
193 .num_cat = ARRAY_SIZE(log_categories),
194};
195
Neels Hofmeyra6078fe2019-01-28 03:52:14 +0100196static struct osmo_tdef gsm_network_T_defs[] = {
197 { .T=3105, .default_val=100, .val=13, .unit=OSMO_TDEF_MS, .desc="Physical Information" },
198 { .T=3212, .default_val=5, .unit=OSMO_TDEF_CUSTOM,
Neels Hofmeyr596c4022018-06-16 19:29:50 +0200199 .desc="Periodic Location Update timer, sent to MS (1 = 6 minutes)" },
200 {}
201};
202
Philippb4cb8382016-09-29 17:01:57 +0200203int main(int argc, char **argv)
204{
205 void *ctx;
206
207 struct gsm_bts *bts;
208 struct gsm_network *net;
209 struct gsm_bts_trx *trx;
210
211 ctx = talloc_named_const(NULL, 0, "ctx");
212
Neels Hofmeyre3416182018-03-05 05:31:14 +0100213 osmo_init_logging2(ctx, &log_info);
214 log_set_log_level(osmo_stderr_target, LOGL_INFO);
215
Philippb4cb8382016-09-29 17:01:57 +0200216 /* Allocate environmental structs (bts, net, trx) */
217 net = talloc_zero(ctx, struct gsm_network);
218 INIT_LLIST_HEAD(&net->bts_list);
Neels Hofmeyr596c4022018-06-16 19:29:50 +0200219 net->T_defs = gsm_network_T_defs;
Philippb4cb8382016-09-29 17:01:57 +0200220 gsm_bts_model_register(&bts_model_nanobts);
221 bts = gsm_bts_alloc_register(net, GSM_BTS_TYPE_NANOBTS, 63);
222 OSMO_ASSERT(bts);
Harald Welte824b2742017-10-01 11:21:16 +0800223 bts->network = net;
Philippb4cb8382016-09-29 17:01:57 +0200224 trx = talloc_zero(ctx, struct gsm_bts_trx);
225
226 /* Parameters needed by nanobts_attr_bts_get() */
227 bts->rach_b_thresh = -1;
228 bts->rach_ldavg_slots = -1;
229 bts->c0->arfcn = 866;
230 bts->cell_identity = 1337;
Neels Hofmeyrf93970b2018-03-05 02:09:40 +0100231 bts->network->plmn = (struct osmo_plmn_id){ .mcc=1, .mnc=1 };
Philippb4cb8382016-09-29 17:01:57 +0200232 bts->location_area_code = 1;
233 bts->gprs.rac = 0;
234 uint8_t attr_bts_expected[] =
235 { 0x19, 0x55, 0x5b, 0x61, 0x67, 0x6d, 0x73, 0x18, 0x06, 0x0e, 0x00,
236 0x02, 0x01, 0x20, 0x33, 0x1e, 0x24, 0x24, 0xa8, 0x34, 0x21,
237 0xa8, 0x1f, 0x3f, 0x25,
Harald Welte5d224582018-02-27 09:56:39 +0100238 0x00, 0x01, 0x0a, 0x0c, 0x0a, 0x0b, 0x01, 0x2a, 0x5a, 0x2b,
Andreas Eversberg30b6df62013-06-12 08:30:53 +0200239 0x03, 0xe8, 0x0a, 0x0d,
Philippb4cb8382016-09-29 17:01:57 +0200240 0x23, 0x0a, 0x08, 0x03, 0x62, 0x09, 0x3f, 0x99, 0x00, 0x07,
241 0x00, 0xf1, 0x10, 0x00,
242 0x01, 0x05, 0x39
243 };
244
245 /* Parameters needed to test nanobts_attr_nse_get() */
246 bts->gprs.nse.nsei = 101;
247 uint8_t attr_nse_expected[] =
248 { 0x9d, 0x00, 0x02, 0x00, 0x65, 0xa0, 0x00, 0x07, 0x03, 0x03, 0x03,
249 0x03, 0x1e, 0x03, 0x0a, 0xa1, 0x00, 0x0b, 0x03, 0x03, 0x03,
250 0x03, 0x03, 0x0a, 0x03,
251 0x0a, 0x03, 0x0a, 0x03
252 };
253
254 /* Parameters needed to test nanobts_attr_cell_get() */
255 bts->gprs.rac = 0x00;
256 bts->gprs.cell.bvci = 2;
257 bts->gprs.mode = BTS_GPRS_GPRS;
258 uint8_t attr_cell_expected[] =
259 { 0x9a, 0x00, 0x01, 0x00, 0x9c, 0x00, 0x02, 0x05, 0x03, 0x9e, 0x00,
260 0x02, 0x00, 0x02, 0xa3, 0x00, 0x09, 0x14, 0x05, 0x05, 0xa0,
261 0x05, 0x0a, 0x04, 0x08,
262 0x0f, 0xa8, 0x00, 0x02, 0x0f, 0x00, 0xa9, 0x00, 0x05, 0x00,
263 0xfa, 0x00, 0xfa, 0x02
264 };
265
266 /* Parameters needed to test nanobts_attr_nscv_get() */
Alexander Couzens2f9df962020-09-21 18:35:24 +0200267 struct osmo_sockaddr_str addr;
268 osmo_sockaddr_str_from_str(&addr, "10.9.1.101", 23000);
269 osmo_sockaddr_str_to_sockaddr(&addr, &bts->gprs.nsvc[0].remote.u.sas);
Philippb4cb8382016-09-29 17:01:57 +0200270 bts->gprs.nsvc[0].nsvci = 0x65;
Philippb4cb8382016-09-29 17:01:57 +0200271 bts->gprs.nsvc[0].local_port = 0x5a3c;
272 uint8_t attr_nscv_expected[] =
273 { 0x9f, 0x00, 0x02, 0x00, 0x65, 0xa2, 0x00, 0x08, 0x59, 0xd8, 0x0a,
274 0x09, 0x01, 0x65, 0x5a, 0x3c
275 };
276
277 /* Parameters needed to test nanobts_attr_radio_get() */
278 trx->arfcn = 866;
279 trx->max_power_red = 22;
280 bts->c0->max_power_red = 22;
281 uint8_t attr_radio_expected[] =
282 { 0x2d, 0x0b, 0x05, 0x00, 0x02, 0x03, 0x62 };
283
284 /* Run tests */
285 test_nanobts_attr_bts_get(bts, attr_bts_expected);
286 test_nanobts_attr_nse_get(bts, attr_nse_expected);
287 test_nanobts_attr_cell_get(bts, attr_cell_expected);
288 test_nanobts_attr_nscv_get(bts, attr_nscv_expected);
289 test_nanobts_attr_radio_get(bts, trx, attr_radio_expected);
290
Alexander Couzens2f9df962020-09-21 18:35:24 +0200291 /* NSVC IPv6 test */
292 struct osmo_sockaddr_str addr6;
293 osmo_sockaddr_str_from_str(&addr6, "fd00:5678:9012:3456:7890:1234:5678:9012", 23010);
294 osmo_sockaddr_str_to_sockaddr(&addr6, &bts->gprs.nsvc[0].remote.u.sas);
295 bts->gprs.nsvc[0].nsvci = 0x65;
296 bts->gprs.nsvc[0].local_port = 0x5a3c;
297 uint8_t attr_nscv6_expected[] =
298 /* |- oml attr |-16bit length */
299 { 0x9f, 0x00, 0x02, 0x00, 0x65, 0xfd, 0x00, 0x16,
300 /* 1b type, 1b padding, 2b local port, 2b remote port */
301 0x29, 0x00, 0x5a, 0x3c, 0x59, 0xe2,
302 /* 128bit / 16b ipv6 address */
303 0xfd, 0x00, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56,
304 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12,
305 };
306 test_nanobts_attr_nscv_get(bts, attr_nscv6_expected);
307
308
Philippb4cb8382016-09-29 17:01:57 +0200309 printf("Done\n");
310 talloc_free(bts);
311 talloc_free(net);
312 talloc_free(trx);
313 talloc_report_full(ctx, stderr);
Neels Hofmeyre3416182018-03-05 05:31:14 +0100314 /* Expecting something like:
315 * full talloc report on 'ctx' (total 813 bytes in 6 blocks)
316 * logging contains 813 bytes in 5 blocks (ref 0) 0x60b0000000a0
317 * struct log_target contains 196 bytes in 2 blocks (ref 0) 0x6110000000a0
318 * struct log_category contains 36 bytes in 1 blocks (ref 0) 0x60d0000003e0
319 * struct log_info contains 616 bytes in 2 blocks (ref 0) 0x60d000000310
320 * struct log_info_cat contains 576 bytes in 1 blocks (ref 0) 0x6170000000e0
321 * That's the root ctx + 5x logging: */
322 OSMO_ASSERT(talloc_total_blocks(ctx) == 6);
323 talloc_free(ctx);
Philippb4cb8382016-09-29 17:01:57 +0200324 return 0;
325}
326
327/* stubs */
328struct osmo_prim_hdr;
329int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx)
330{
331 abort();
332}
Harald Welte3561bd42018-01-28 03:04:16 +0100333
334struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *net) {
335 OSMO_ASSERT(0);
336}
Neels Hofmeyr958f2592018-05-27 01:26:31 +0200337
338bool on_gsm_ts_init(struct gsm_bts_trx_ts *ts)
339{ return true; }
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200340
341void ts_fsm_alloc(struct gsm_bts_trx_ts *ts) {}
Pau Espin Pedrolf8d03892019-11-12 16:30:30 +0100342int rsl_chan_ms_power_ctrl(struct gsm_lchan *lchan) { return 0; }
Pau Espin Pedrol8d4f94a2020-07-16 15:17:20 +0200343void pcu_info_update(struct gsm_bts *bts) {};
344int rsl_sacch_filling(struct gsm_bts_trx *trx, uint8_t type, const uint8_t *data, int len) { return 0; }
345int rsl_bcch_info(const struct gsm_bts_trx *trx, enum osmo_sysinfo_type si_type, const uint8_t *data, int len)
346{ return 0; }
347int gsm_generate_si(struct gsm_bts *bts, enum osmo_sysinfo_type si_type) { return 0; }