blob: 674148a251d90ef63383f2e65a9d71320fc6bc52 [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>
Philippb4cb8382016-09-29 17:01:57 +020025
26#include <osmocom/core/talloc.h>
27#include <osmocom/core/utils.h>
28#include <osmocom/core/application.h>
29
30#include <stdio.h>
31#include <string.h>
32
33struct gsm_bts_model bts_model_nanobts = {
34 .type = GSM_BTS_TYPE_NANOBTS,
35 .name = "nanobts",
36 .start = NULL,
37 .oml_rcvmsg = NULL,
38 .e1line_bind_ops = NULL,
39 .nm_att_tlvdef = {
40 .def = {
41 /* ip.access specifics */
42 [NM_ATT_IPACC_DST_IP] = {TLV_TYPE_FIXED, 4},
43 [NM_ATT_IPACC_DST_IP_PORT] =
44 {TLV_TYPE_FIXED, 2},
45 [NM_ATT_IPACC_STREAM_ID] = {TLV_TYPE_TV,},
46 [NM_ATT_IPACC_SEC_OML_CFG] =
47 {TLV_TYPE_FIXED, 6},
48 [NM_ATT_IPACC_IP_IF_CFG] =
49 {TLV_TYPE_FIXED, 8},
50 [NM_ATT_IPACC_IP_GW_CFG] =
51 {TLV_TYPE_FIXED, 12},
52 [NM_ATT_IPACC_IN_SERV_TIME] =
53 {TLV_TYPE_FIXED, 4},
54 [NM_ATT_IPACC_LOCATION] = {TLV_TYPE_TL16V},
55 [NM_ATT_IPACC_PAGING_CFG] =
56 {TLV_TYPE_FIXED, 2},
57 [NM_ATT_IPACC_UNIT_ID] = {TLV_TYPE_TL16V},
58 [NM_ATT_IPACC_UNIT_NAME] = {TLV_TYPE_TL16V},
59 [NM_ATT_IPACC_SNMP_CFG] = {TLV_TYPE_TL16V},
60 [NM_ATT_IPACC_PRIM_OML_CFG_LIST] =
61 {TLV_TYPE_TL16V},
62 [NM_ATT_IPACC_NV_FLAGS] = {TLV_TYPE_TL16V},
63 [NM_ATT_IPACC_FREQ_CTRL] =
64 {TLV_TYPE_FIXED, 2},
65 [NM_ATT_IPACC_PRIM_OML_FB_TOUT] =
66 {TLV_TYPE_TL16V},
67 [NM_ATT_IPACC_CUR_SW_CFG] = {TLV_TYPE_TL16V},
68 [NM_ATT_IPACC_TIMING_BUS] = {TLV_TYPE_TL16V},
69 [NM_ATT_IPACC_CGI] = {TLV_TYPE_TL16V},
70 [NM_ATT_IPACC_RAC] = {TLV_TYPE_TL16V},
71 [NM_ATT_IPACC_OBJ_VERSION] = {TLV_TYPE_TL16V},
72 [NM_ATT_IPACC_GPRS_PAGING_CFG] =
73 {TLV_TYPE_TL16V},
74 [NM_ATT_IPACC_NSEI] = {TLV_TYPE_TL16V},
75 [NM_ATT_IPACC_BVCI] = {TLV_TYPE_TL16V},
76 [NM_ATT_IPACC_NSVCI] = {TLV_TYPE_TL16V},
77 [NM_ATT_IPACC_NS_CFG] = {TLV_TYPE_TL16V},
78 [NM_ATT_IPACC_BSSGP_CFG] = {TLV_TYPE_TL16V},
79 [NM_ATT_IPACC_NS_LINK_CFG] = {TLV_TYPE_TL16V},
80 [NM_ATT_IPACC_RLC_CFG] = {TLV_TYPE_TL16V},
81 [NM_ATT_IPACC_ALM_THRESH_LIST] =
82 {TLV_TYPE_TL16V},
83 [NM_ATT_IPACC_MONIT_VAL_LIST] =
84 {TLV_TYPE_TL16V},
85 [NM_ATT_IPACC_TIB_CONTROL] = {TLV_TYPE_TL16V},
86 [NM_ATT_IPACC_SUPP_FEATURES] =
87 {TLV_TYPE_TL16V},
88 [NM_ATT_IPACC_CODING_SCHEMES] =
89 {TLV_TYPE_TL16V},
90 [NM_ATT_IPACC_RLC_CFG_2] = {TLV_TYPE_TL16V},
91 [NM_ATT_IPACC_HEARTB_TOUT] = {TLV_TYPE_TL16V},
92 [NM_ATT_IPACC_UPTIME] = {TLV_TYPE_TL16V},
93 [NM_ATT_IPACC_RLC_CFG_3] = {TLV_TYPE_TL16V},
94 [NM_ATT_IPACC_SSL_CFG] = {TLV_TYPE_TL16V},
95 [NM_ATT_IPACC_SEC_POSSIBLE] =
96 {TLV_TYPE_TL16V},
97 [NM_ATT_IPACC_IML_SSL_STATE] =
98 {TLV_TYPE_TL16V},
99 [NM_ATT_IPACC_REVOC_DATE] = {TLV_TYPE_TL16V},
100 },
101 },
102};
103
104static void test_nanobts_attr_bts_get(struct gsm_bts *bts, uint8_t *expected)
105{
106 struct msgb *msgb;
107
108 printf("Testing nanobts_attr_bts_get()...\n");
109
110 msgb = nanobts_attr_bts_get(bts);
111 printf("result= %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
112 printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
113 OSMO_ASSERT(memcmp(msgb->data, expected, msgb->len) == 0);
114 msgb_free(msgb);
115
116 printf("ok.\n");
117 printf("\n");
118}
119
120static void test_nanobts_attr_nse_get(struct gsm_bts *bts, uint8_t *expected)
121{
122 struct msgb *msgb;
123
124 printf("Testing nanobts_attr_nse_get()...\n");
125
126 msgb = nanobts_attr_nse_get(bts);
127 printf("result= %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
128 printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
129 OSMO_ASSERT(memcmp(msgb->data, expected, msgb->len) == 0);
130 msgb_free(msgb);
131
132 printf("ok.\n");
133 printf("\n");
134}
135
136static void test_nanobts_attr_cell_get(struct gsm_bts *bts, uint8_t *expected)
137{
138 struct msgb *msgb;
139
140 printf("Testing nanobts_attr_cell_get()...\n");
141
142 msgb = nanobts_attr_cell_get(bts);
143 printf("result= %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
144 printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
145 OSMO_ASSERT(memcmp(msgb->data, expected, msgb->len) == 0);
146 msgb_free(msgb);
147
148 printf("ok.\n");
149 printf("\n");
150}
151
152static void test_nanobts_attr_nscv_get(struct gsm_bts *bts, uint8_t *expected)
153{
154 struct msgb *msgb;
155
156 printf("Testing nanobts_attr_nscv_get()...\n");
157
158 msgb = nanobts_attr_nscv_get(bts);
159 printf("result= %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
160 printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
161 OSMO_ASSERT(memcmp(msgb->data, expected, msgb->len) == 0);
162 msgb_free(msgb);
163
164 printf("ok.\n");
165 printf("\n");
166}
167
168static void test_nanobts_attr_radio_get(struct gsm_bts *bts,
169 struct gsm_bts_trx *trx,
170 uint8_t *expected)
171{
172 struct msgb *msgb;
173
174 printf("Testing nanobts_attr_nscv_get()...\n");
175
176 msgb = nanobts_attr_radio_get(bts, trx);
177 printf("result= %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
178 printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
179 OSMO_ASSERT(memcmp(msgb->data, expected, msgb->len) == 0);
180 msgb_free(msgb);
181
182 printf("ok.\n");
183 printf("\n");
184}
185
186int main(int argc, char **argv)
187{
188 void *ctx;
189
190 struct gsm_bts *bts;
191 struct gsm_network *net;
192 struct gsm_bts_trx *trx;
193
Harald Weltef2b04c62017-10-03 15:45:30 +0800194 osmo_init_logging(&log_info);
195 log_set_log_level(osmo_stderr_target, LOGL_INFO);
196
Philippb4cb8382016-09-29 17:01:57 +0200197 ctx = talloc_named_const(NULL, 0, "ctx");
198
199 /* Allocate environmental structs (bts, net, trx) */
200 net = talloc_zero(ctx, struct gsm_network);
201 INIT_LLIST_HEAD(&net->bts_list);
202 gsm_bts_model_register(&bts_model_nanobts);
203 bts = gsm_bts_alloc_register(net, GSM_BTS_TYPE_NANOBTS, 63);
204 OSMO_ASSERT(bts);
Harald Welte824b2742017-10-01 11:21:16 +0800205 bts->network = net;
Philippb4cb8382016-09-29 17:01:57 +0200206 trx = talloc_zero(ctx, struct gsm_bts_trx);
207
208 /* Parameters needed by nanobts_attr_bts_get() */
209 bts->rach_b_thresh = -1;
210 bts->rach_ldavg_slots = -1;
211 bts->c0->arfcn = 866;
212 bts->cell_identity = 1337;
213 bts->network->country_code = 1;
214 bts->network->network_code = 1;
215 bts->location_area_code = 1;
216 bts->gprs.rac = 0;
217 uint8_t attr_bts_expected[] =
218 { 0x19, 0x55, 0x5b, 0x61, 0x67, 0x6d, 0x73, 0x18, 0x06, 0x0e, 0x00,
219 0x02, 0x01, 0x20, 0x33, 0x1e, 0x24, 0x24, 0xa8, 0x34, 0x21,
220 0xa8, 0x1f, 0x3f, 0x25,
221 0x00, 0x01, 0x0a, 0x0c, 0x0a, 0x0b, 0x01, 0x2a, 0x0a, 0x2b,
Andreas Eversberg30b6df62013-06-12 08:30:53 +0200222 0x03, 0xe8, 0x0a, 0x0d,
Philippb4cb8382016-09-29 17:01:57 +0200223 0x23, 0x0a, 0x08, 0x03, 0x62, 0x09, 0x3f, 0x99, 0x00, 0x07,
224 0x00, 0xf1, 0x10, 0x00,
225 0x01, 0x05, 0x39
226 };
227
228 /* Parameters needed to test nanobts_attr_nse_get() */
229 bts->gprs.nse.nsei = 101;
230 uint8_t attr_nse_expected[] =
231 { 0x9d, 0x00, 0x02, 0x00, 0x65, 0xa0, 0x00, 0x07, 0x03, 0x03, 0x03,
232 0x03, 0x1e, 0x03, 0x0a, 0xa1, 0x00, 0x0b, 0x03, 0x03, 0x03,
233 0x03, 0x03, 0x0a, 0x03,
234 0x0a, 0x03, 0x0a, 0x03
235 };
236
237 /* Parameters needed to test nanobts_attr_cell_get() */
238 bts->gprs.rac = 0x00;
239 bts->gprs.cell.bvci = 2;
240 bts->gprs.mode = BTS_GPRS_GPRS;
241 uint8_t attr_cell_expected[] =
242 { 0x9a, 0x00, 0x01, 0x00, 0x9c, 0x00, 0x02, 0x05, 0x03, 0x9e, 0x00,
243 0x02, 0x00, 0x02, 0xa3, 0x00, 0x09, 0x14, 0x05, 0x05, 0xa0,
244 0x05, 0x0a, 0x04, 0x08,
245 0x0f, 0xa8, 0x00, 0x02, 0x0f, 0x00, 0xa9, 0x00, 0x05, 0x00,
246 0xfa, 0x00, 0xfa, 0x02
247 };
248
249 /* Parameters needed to test nanobts_attr_nscv_get() */
250 bts->gprs.nsvc[0].nsvci = 0x65;
251 bts->gprs.nsvc[0].remote_port = 0x59d8;
252 bts->gprs.nsvc[0].remote_ip = 0x0a090165;
253 bts->gprs.nsvc[0].local_port = 0x5a3c;
254 uint8_t attr_nscv_expected[] =
255 { 0x9f, 0x00, 0x02, 0x00, 0x65, 0xa2, 0x00, 0x08, 0x59, 0xd8, 0x0a,
256 0x09, 0x01, 0x65, 0x5a, 0x3c
257 };
258
259 /* Parameters needed to test nanobts_attr_radio_get() */
260 trx->arfcn = 866;
261 trx->max_power_red = 22;
262 bts->c0->max_power_red = 22;
263 uint8_t attr_radio_expected[] =
264 { 0x2d, 0x0b, 0x05, 0x00, 0x02, 0x03, 0x62 };
265
266 /* Run tests */
267 test_nanobts_attr_bts_get(bts, attr_bts_expected);
268 test_nanobts_attr_nse_get(bts, attr_nse_expected);
269 test_nanobts_attr_cell_get(bts, attr_cell_expected);
270 test_nanobts_attr_nscv_get(bts, attr_nscv_expected);
271 test_nanobts_attr_radio_get(bts, trx, attr_radio_expected);
272
273 printf("Done\n");
274 talloc_free(bts);
275 talloc_free(net);
276 talloc_free(trx);
277 talloc_report_full(ctx, stderr);
278 OSMO_ASSERT(talloc_total_blocks(ctx) == 1);
279 return 0;
280}
281
282/* stubs */
283struct osmo_prim_hdr;
284int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx)
285{
286 abort();
287}