aboutsummaryrefslogtreecommitdiffstats
path: root/tests/nanobts_omlattr/nanobts_omlattr_test.c
blob: fe5ee8873280ae7f4a3c007a464a741f4a677ae9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/* Test OML attribute generator */

/* (C) 2016 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
 * All Rights Reserved
 *
 * Author: Philipp Maier
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <osmocom/bsc/debug.h>
#include <osmocom/bsc/gsm_data.h>
#include <osmocom/bsc/bts_ipaccess_nanobts_omlattr.h>
#include <osmocom/bsc/bts.h>

#include <osmocom/core/talloc.h>
#include <osmocom/core/tdef.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/application.h>
#include <osmocom/core/sockaddr_str.h>

#include <stdio.h>
#include <string.h>

extern struct gsm_bts_model bts_model_nanobts;
extern void bts_gprs_timer_groups_init(struct gsm_bts *bts);
extern void bts_grprs_tdef_groups_init(void);

static void test_nanobts_gen_set_bts_attr(struct gsm_bts *bts, uint8_t *expected)
{
	struct msgb *msgb;

	printf("Testing nanobts_gen_set_bts_attr()...\n");

	msgb = nanobts_gen_set_bts_attr(bts);
	printf("result=  %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
	printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
	OSMO_ASSERT(msgb_eq_data_print(msgb, expected, msgb->len));
	msgb_free(msgb);

	printf("ok.\n");
	printf("\n");
}

static void test_nanobts_gen_set_nse_attr(struct gsm_bts *bts, uint8_t *expected)
{
	struct msgb *msgb;

	printf("Testing nanobts_gen_set_nse_attr()...\n");

	msgb = nanobts_gen_set_nse_attr(bts->site_mgr);
	printf("result=  %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
	printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
	OSMO_ASSERT(msgb_eq_data_print(msgb, expected, msgb->len));
	msgb_free(msgb);

	printf("ok.\n");
	printf("\n");
}

static void test_nanobts_gen_set_cell_attr(struct gsm_bts *bts, uint8_t *expected)
{
	struct msgb *msgb;

	printf("Testing nanobts_gen_set_cell_attr()...\n");

	bts->gprs.cell.mo.ipaccess.obj_version = 30;

	msgb = nanobts_gen_set_cell_attr(bts);
	printf("result=  %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
	printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
	OSMO_ASSERT(msgb_eq_data_print(msgb, expected, msgb->len));
	msgb_free(msgb);

	printf("ok.\n");
	printf("\n");
}

static void test_nanobts_gen_set_nsvc_attr(struct gsm_bts *bts, uint8_t *expected)
{
	struct msgb *msgb;

	printf("Testing nanobts_gen_set_nsvc_attr()...\n");

	msgb = nanobts_gen_set_nsvc_attr(&bts->site_mgr->gprs.nsvc[0]);
	printf("result=  %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
	printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
	OSMO_ASSERT(msgb_eq_data_print(msgb, expected, msgb->len));
	msgb_free(msgb);

	printf("ok.\n");
	printf("\n");
}

static void test_nanobts_gen_set_radio_attr(struct gsm_bts *bts,
					struct gsm_bts_trx *trx,
					uint8_t *expected)
{
	struct msgb *msgb;

	printf("Testing nanobts_gen_set_nsvc_attr()...\n");

	msgb = nanobts_gen_set_radio_attr(bts, trx);
	printf("result=  %s\n", osmo_hexdump_nospc(msgb->data, msgb->len));
	printf("expected=%s\n", osmo_hexdump_nospc(expected, msgb->len));
	OSMO_ASSERT(msgb_eq_data_print(msgb, expected, msgb->len));
	msgb_free(msgb);

	printf("ok.\n");
	printf("\n");
}

static const struct log_info_cat log_categories[] = {
};

static const struct log_info log_info = {
	.cat = log_categories,
	.num_cat = ARRAY_SIZE(log_categories),
};

static struct osmo_tdef gsm_network_T_defs[] = {
	{ .T = 3105, .default_val = GSM_T3105_DEFAULT, .val = GSM_T3105_DEFAULT, .min_val = 0, .max_val = UINT8_MAX, .unit = OSMO_TDEF_MS, .desc = "Physical Information" },
	{ .T = 3212, .default_val = 5, .unit = OSMO_TDEF_CUSTOM, .min_val = 0, .max_val = UINT8_MAX,
		.desc = "Periodic Location Update timer, sent to MS (1 = 6 minutes)" },
	{ .T = -3105, .default_val = GSM_NY1_DEFAULT, .val = GSM_NY1_DEFAULT, .min_val = 0, .max_val = UINT8_MAX, .unit = OSMO_TDEF_CUSTOM,
		.desc = "Ny1: Maximum number of Physical Information (re)transmissions" },
	{ .T = 3142, .default_val = 20, .desc = "Used during packet access on CCCH/while in dedicated mode. "
						"Started after the receipt of IMMEDIATE ASSIGNMENT REJECT or DTM "
						"REJECT or EC IMMEDIATE ASSIGNMENT REJECT" },
	{ .T = 3169, .default_val = 5, .desc = "Release radio resource (TFI, USF) timer (linked to N3103, N3103)" },
	{ .T = 3191, .default_val = 5, .desc = "Downlink TBF Release downlink RLC data block retransmission timer" },
	{ .T = 3193, .default_val = 1600, .desc = "Downlink TBF Release timer", .unit = OSMO_TDEF_MS },
	{ .T = 3195, .default_val = 5, .desc = "Timer for TFI release on N3105 overflow (unresponsive MS)" },
	{ .T = GSM_BTS_TDEF_ID_COUNTDOWN_VALUE, .default_val = 15, .desc = "CV: Countdown value/remaining blocks to transmit",
	  .unit = OSMO_TDEF_CUSTOM, .max_val = UINT8_MAX },
	{ .T = GSM_BTS_TDEF_ID_UL_TBF_EXT, .default_val = 2500,
	  .desc = "\"In the extended uplink TBF mode, the uplink TBF may be maintained during temporary inactive periods, "
		  "where the mobile station has no RLC information to send.\" (3GPP TS 44.060 Version 6.14.0)",
	  .unit = OSMO_TDEF_MS, .max_val = 500 * 10 },
	{ .T = GSM_BTS_TDEF_ID_DL_TBF_DELAYED, .default_val = 2500,
	  .desc = "A delayed release of the downlink TBF is when the release of the downlink TBF is delayed following the transmission of a final data block, "
		  "rather than instantly releasing the TBF",
	{ .T = 3101, .default_val = 10, .desc = "N3101: Maximum USFs without response from the MS", .unit = OSMO_TDEF_CUSTOM,
	  .min_val = GSM_RLCMACN3101_STRICT_LOWER_BOUND + 1 },
	{ .T = 3103, .default_val = 4, .desc = "N3103: Maximum PACKET UPLINK ACK/NACK messages within a TBF unacknowledged by MS",
	  .unit = OSMO_TDEF_CUSTOM},
	{ .T = 3105, .default_val = 8, .desc = "N3105: Maximum allocated data blocks without RLC/MAC control reply from MS",
	  .unit = OSMO_TDEF_CUSTOM },
	{ .T = GSM_BTS_TDEF_ID_TNS_BLOCK, .default_val = 3, .max_val = UINT8_MAX,
	  .desc = "Tns-block: Guards the blocking and unblocking procedures" },
	{ .T = GSM_BTS_TDEF_ID_TNS_BLOCK_RETRIES, .default_val = 3, .max_val = UINT8_MAX,
	  .desc = "NS-BLOCK-RETRIES: Blocking procedure retries", .unit = OSMO_TDEF_CUSTOM },
	{ .T = GSM_BTS_TDEF_ID_TNS_RESET, .default_val = 3, .max_val = UINT8_MAX,
	  .desc = "Tns-reset: Guards the reset procedure" },
	{ .T = GSM_BTS_TDEF_ID_TNS_RESET_RETRIES, .default_val = 3, .max_val = UINT8_MAX,
	  .desc = "Reset procedure retries", .unit = OSMO_TDEF_CUSTOM },
	{ .T = GSM_BTS_TDEF_ID_TNS_TEST, .default_val = 30, .max_val = UINT8_MAX,
	  .desc = "Tns-test: Periodicity of the NS-VC test procedure" },
	{ .T = GSM_BTS_TDEF_ID_TNS_ALIVE, .default_val = 3, .max_val = UINT8_MAX,
	  .desc = "Tns-alive: Guards the NS-VC test procedure" },
	{ .T = GSM_BTS_TDEF_ID_TNS_ALIVE_RETRIES, .default_val = 10, .max_val = UINT8_MAX,
	  .desc = "NS-ALIVE-RETRIES: Retries for the the NS-VC test procedure", .unit = OSMO_TDEF_CUSTOM },
	{}
};

int main(int argc, char **argv)
{
	void *ctx;

	struct gsm_bts *bts;
	struct gsm_network *net;
	struct gsm_bts_trx *trx;

	ctx = talloc_named_const(NULL, 0, "ctx");

	osmo_init_logging2(ctx, &log_info);
	log_set_log_level(osmo_stderr_target, LOGL_INFO);

	/* Allocate environmental structs (bts, net, trx) */
	net = talloc_zero(ctx, struct gsm_network);
	INIT_LLIST_HEAD(&net->bts_list);
	osmo_tdefs_reset(net->T_defs = gsm_network_T_defs);
	bts_grprs_tdef_groups_init();
	gsm_bts_model_register(&bts_model_nanobts);
	bts = gsm_bts_alloc_register(net, GSM_BTS_TYPE_NANOBTS, 63);
	bts_gprs_timer_groups_init(bts);
	OSMO_ASSERT(bts);
	bts->network = net;
	trx = talloc_zero(ctx, struct gsm_bts_trx);

	/* Parameters needed by nanobts_gen_set_bts_attr() */
	bts->rach_b_thresh = -1;
	bts->rach_ldavg_slots = -1;
	bts->c0->arfcn = 866;
	bts->cell_identity = 1337;
	bts->network->plmn = (struct osmo_plmn_id){ .mcc=1, .mnc=1 };
	bts->location_area_code = 0x0001;
	bts->gprs.rac = 0;
	uint8_t attr_bts_expected[] =
	    { 0x19, 0x73, 0x6d, 0x67, 0x61, 0x5b, 0x55,
	      /* 0x18 Intave Parameter */
	      0x18, 0x06,
	      /* 0x0e: Connection Failure Criterion, rlt == 0x20 */
	      0x0e, 0x00, 0x02, 0x01, 0x20,
	      /* 0x33: T200 */
	      0x33, 0x1e, 0x24, 0x24, 0xa8, 0x34, 0x21, 0xa8,
	      /* 0x1f: Max Timing Advance */
	      0x1f, 0x3f,
	      /* 0x25: Overload Period */
	      0x25, 0x00, 0x01, 0x0a,
	      /* 0x0c CCCH Load Threshold */
	      0x0c, 0x0a,
	      /* 0x0b CCCH Load Indication Period */
	      0x0b, 0x01,
	      /* 0x2a: RACH Busy Threshold */
	      0x2a, 0x5a,
	      /* 0x2b: RACH Load Averaging Slots */
	      0x2b, 0x03, 0xe8,
	      /* 0x0a: BTS Air Timer */
	      0x0a, 0x0a,
	      /* Ny1 */
	      0x23, 0x11,
	      0x08, 0x03, 0x62, 0x09, 0x3f, 0x99, 0x00, 0x07,
	      0x00, 0xf1, 0x10, 0x00, 0x01, 0x05, 0x39
	};

	/* Parameters needed to test nanobts_gen_set_nse_attr() */
	bts->site_mgr->gprs.nse.nsei = 101;
	uint8_t attr_nse_expected[] = {
		/*			      NM_ATT_IPACC_NS_CFG */
		0x9d, 0x00, 0x02, 0x00, 0x65, 0xa0,
		/* LEN1, LEN2 */
		   0x00, 0x07,
		/* TNS BLK, TNS BLK RE, TNS_RST, TNS_RST_RE, TNS_TEST */
		   0x03,    0x03,	0x03,	 0x03,	     0x1e,
		/* TNS ALIVE, TNS ALIVE_RE */
		   0x03,      0x0a,
		0xa1, 0x00, 0x0b, 0x03, 0x03, 0x03,
		0x03, 0x03, 0x0a, 0x03,
		0x0a, 0x03, 0x0a, 0x03
	};

	/* Parameters needed to test nanobts_gen_set_cell_attr() */
	bts->gprs.rac = 0x00;
	bts->gprs.cell.bvci = 2;
	bts->gprs.mode = BTS_GPRS_GPRS;
	uint8_t attr_cell_expected[] = {
		   0x9a,  0x00,  0x01,  0x00,	  0x9c,	 0x00,	0x02,  0x05,  0x03, 0x9e, 0x00,
		   0x02,  0x00,  0x02,  0xa3,	  0x00,	 0x09,
		/* T3142, T3169, T3191, T3193/10, T3195, N3101, N3103, N3105, CV  */
		   0x14,  0x05,  0x05,  0xa0,	  0x05,	 0x0a,	0x04,  0x08,  0x0f,
		   0xa8,  0x00,  0x02,  0x0f,	  0x00,	 0xa9,	0x00,  0x05,  0x00,
		   0xfa,  0x00,  0xfa,  0x02,	  0xac,	 0x00,	0x01,  0x06,
	};

	/* Parameters needed to test nanobts_gen_set_nsvc_attr() */
	struct osmo_sockaddr_str addr;
	osmo_sockaddr_str_from_str(&addr, "10.9.1.101", 23000);
	osmo_sockaddr_str_to_sockaddr(&addr, &bts->site_mgr->gprs.nsvc[0].remote.u.sas);
	bts->site_mgr->gprs.nsvc[0].nsvci = 0x65;
	bts->site_mgr->gprs.nsvc[0].local_port = 0x5a3c;
	uint8_t attr_nscv_expected[] =
	    { 0x9f, 0x00, 0x02, 0x00, 0x65, 0xa2, 0x00, 0x08, 0x59, 0xd8, 0x0a,
		0x09, 0x01, 0x65, 0x5a, 0x3c
	};

	/* Parameters needed to test nanobts_gen_set_radio_attr() */
	trx->arfcn = 866;
	trx->max_power_red = 22;
	bts->c0->max_power_red = 22;
	uint8_t attr_radio_expected[] =
	    { 0x2d, 0x0b, 0x05, 0x00, 0x02, 0x03, 0x62 };

	/* Run tests */
	test_nanobts_gen_set_bts_attr(bts, attr_bts_expected);
	test_nanobts_gen_set_nse_attr(bts, attr_nse_expected);
	test_nanobts_gen_set_cell_attr(bts, attr_cell_expected);
	test_nanobts_gen_set_nsvc_attr(bts, attr_nscv_expected);
	test_nanobts_gen_set_radio_attr(bts, trx, attr_radio_expected);

	/* NSVC IPv6 test */
	struct osmo_sockaddr_str addr6;
	osmo_sockaddr_str_from_str(&addr6, "fd00:5678:9012:3456:7890:1234:5678:9012", 23010);
	osmo_sockaddr_str_to_sockaddr(&addr6, &bts->site_mgr->gprs.nsvc[0].remote.u.sas);
	bts->site_mgr->gprs.nsvc[0].nsvci = 0x65;
	bts->site_mgr->gprs.nsvc[0].local_port = 0x5a3c;
	uint8_t attr_nscv6_expected[] =
	      /*                             |- oml attr  |-16bit length */
	    { 0x9f, 0x00, 0x02, 0x00, 0x65, 0xfd, 0x00, 0x16,
	      /* 1b type, 1b padding, 2b local port, 2b remote port */
	      0x29, 0x00, 0x5a, 0x3c, 0x59, 0xe2,
	      /* 128bit / 16b ipv6 address */
	      0xfd, 0x00, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56,
	      0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12,
	    };
	test_nanobts_gen_set_nsvc_attr(bts, attr_nscv6_expected);


	printf("Done\n");
	talloc_free(bts);
	talloc_free(net);
	talloc_free(trx);
	talloc_report_full(ctx, stderr);
	/* Expecting something like:
	 * full talloc report on 'ctx' (total    813 bytes in   6 blocks)
	 *     logging                        contains    813 bytes in   5 blocks (ref 0) 0x60b0000000a0
	 * 	struct log_target              contains    196 bytes in   2 blocks (ref 0) 0x6110000000a0
	 * 	    struct log_category            contains     36 bytes in   1 blocks (ref 0) 0x60d0000003e0
	 * 	struct log_info                contains    616 bytes in   2 blocks (ref 0) 0x60d000000310
	 * 	    struct log_info_cat            contains    576 bytes in   1 blocks (ref 0) 0x6170000000e0
	 * That's the root ctx + 5x logging: */
	OSMO_ASSERT(talloc_total_blocks(ctx) == 6);
	talloc_free(ctx);
	return 0;
}