aboutsummaryrefslogtreecommitdiffstats
path: root/cbc/CBC_Tests.ttcn
blob: ed63323d7af67ada77e16523867c914b3bdf80c8 (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
module CBC_Tests {

import from Osmocom_Types all;

import from BSSAP_Types all;
import from CBSP_Types all;
import from CBSP_Templates all;
import from CBSP_Adapter all;
import from CBSP_CodecPort all;

modulepar {
	charstring mp_cbc_host := "127.0.0.1";
	integer mp_cbc_port := 48049;
};

type component test_CT extends CBSP_Adapter_CT {
};

altstep as_cbsp_reset(integer idx) runs on CBSP_Adapter_CT {
	var CBSP_RecvFrom rf;
	[] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], tr_CBSP_RESET)) -> value rf {
		var CBSP_IE ie;
		f_cbsp_find_ie(rf.msg, CBSP_IEI_CELL_LIST, ie);
		CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx],
				ts_CBSP_RESET_COMPL(ie.body.cell_list.cell_id)));
	}
}

/* receive + acknowledge KEEP-ALIVE */
altstep as_cbsp_keepalive_ack(integer idx) runs on CBSP_Adapter_CT {
	[] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], tr_CBSP_KEEP_ALIVE)) {
		CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx], ts_CBSP_KEEP_ALIVE_COMPL));
	}
}

/* receive + ignore RESTART */
altstep as_cbsp_restart(integer idx) runs on CBSP_Adapter_CT {
	[] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], tr_CBSP_RESTART));
}

private function f_init(boolean raw := false) runs on test_CT {
	CBSP_Adapter.f_connect(mp_cbc_host, mp_cbc_port, "", -1);

	if (not raw) {
		var BSSMAP_FIELD_CellIdentificationList cell_list := {
			cIl_allInBSS := ''O
		};
		activate(as_cbsp_keepalive_ack(0));
		activate(as_cbsp_restart(0));
		f_cbsp_send(ts_CBSP_RESTART(cell_list, CBSP_BC_MSGT_CBS, CBSP_RI_DATA_LOST));
		f_cbsp_send(ts_CBSP_RESTART(cell_list, CBSP_BC_MSGT_EMERG, CBSP_RI_DATA_LOST));
		as_cbsp_reset(0);
	}
}

testcase TC_foo() runs on test_CT {
	f_init();
	f_sleep(10.0);
}

/* test whether or not we receive a KEEP-ALIVE at all */
testcase TC_rx_keepalive() runs on test_CT {
	f_init(raw := true);
	f_cbsp_exp(tr_CBSP_KEEP_ALIVE(?));
	setverdict(pass);
}

testcase TC_rx_keepalive_timeout() runs on test_CT {
	var CBSP_PDU rx;
	var CBSP_IE ie;

	f_init(raw := true);
	rx := f_cbsp_exp(tr_CBSP_KEEP_ALIVE(?));
	f_cbsp_find_ie(rx, CBSP_IEI_KEEP_ALIVE_REP_PERIOD, ie);

	setverdict(pass);
}

type record CBS_Message {
	uint16_t msg_id,
	uint16_t ser_nr,
	BSSMAP_FIELD_CellIdentificationList cell_list,
	uint8_t channel_ind,
	CBSP_Category category,
	uint16_t rep_period,
	uint16_t num_bcast_req,
	uint8_t dcs,
	CBS_MessageContents content
};
type record CBS_MessageContent {
	octetstring payload,
	uint8_t user_len
};
type record of CBS_MessageContent CBS_MessageContents;

private function f_cbsp_write(CBS_Message msg, integer idx := 0) runs on test_CT {
	var template CBSP_IEs content_ies := {};
	var template (present) CBSP_PDU rx_templ;
	var CBSP_RecvFrom rf;
	for (var integer i := 0; i < lengthof(msg.content); i := i+1) {
		//content_ies[i] := tr_CbspMsgContent(msg.content[i].payload, msg.content[i].user_len);
		content_ies[i] := tr_CbspMsgContent(?, ?);
	}
	rx_templ := tr_CBSP_WRITE_CBS(msg.msg_id, msg.ser_nr, msg.cell_list, msg.channel_ind,
				      msg.category, msg.rep_period, msg.num_bcast_req, msg.dcs,
				      content_ies);
	alt {
	[] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], rx_templ)) -> value rf {
		template (value) CBSP_PDU tx := ts_CBSP_WRITE_CBS_COMPL(msg.msg_id, msg.ser_nr, msg.cell_list, msg.channel_ind);
		CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx], tx));
		}
	[] CBSP[idx].receive {
		setverdict(fail, "Received unexpected CBSP");
		}
	}
}

private const BSSMAP_FIELD_CellIdentificationList cil_BSS := {
	cIl_allInBSS := ''O
};

testcase TC_write_replace() runs on test_CT {
	f_init();
	var CBS_Message msg := {
		msg_id := 42,
		ser_nr := 16752,
		cell_list := cil_BSS,
		channel_ind := 0,
		category := CBSP_CATEG_NORMAL,
		rep_period := 5,
		num_bcast_req := 3,
		dcs := 1,
		content := {
			{ '00'O, 1 }
		}
	};
	f_cbsp_write(msg);
	f_sleep(100.0);
}

testcase TC_selftest() runs on test_CT {
	const octetstring c_load_q := '0700000d0400080000f110012345671200'O;
	const octetstring c_load_q_compl := '0800000f0a000a0000f1100123456700001200'O;
	const octetstring c_reset := '1000000b0400080000f11001234567'O;
	const octetstring c_reset_compl := '1100000b0400080000f11001234567'O;
	const octetstring c_msg_sts_q := '0a0000130e022b0200000400080000f110012345671200'O;
	const octetstring c_msg_sts_q_fail := '0c0000140e022b0200000900090000f11001234567021200'O;
	const octetstring c_kill := '040000110e00000200000400080000f11001234567'O;
	const octetstring c_kill_fail := '060000120e00000200000900090000f1100123456702'O;
	const octetstring c_write_repl := '010000c70e022b0300300400080000f110012345671200050006000407000613020c400107f4f29c9e769f5de337b90c921d1b8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d100'O;
	const octetstring c_write_repl_compl := '020000130e022b0300300400080000f110012345671200'O;
	const octetstring c_write_repl_fail := '030000140e022b0300300900090000f110012345670d1200'O;
	const octetstring c_msg_s_q := '0a0000130e022b0200900400080000f110012345671200'O;
	const octetstring c_msg_s_q_compl := '0b0000160e022b02009008000b0000f110012345670008001200'O;
	const octetstring c_kill_compl := '050000160e022b02008008000b0000f110012345670006001200'O;

	log(dec_CBSP_PDU(c_load_q));
	log(dec_CBSP_PDU(c_load_q_compl));
	log(dec_CBSP_PDU(c_reset));
	log(dec_CBSP_PDU(c_reset_compl));
	log(dec_CBSP_PDU(c_msg_sts_q));
	log(dec_CBSP_PDU(c_msg_sts_q_fail));
	log(dec_CBSP_PDU(c_kill));
	log(dec_CBSP_PDU(c_kill_fail));
	log(dec_CBSP_PDU(c_write_repl));
	log(dec_CBSP_PDU(c_write_repl_compl));
	log(dec_CBSP_PDU(c_write_repl_fail));
	log(dec_CBSP_PDU(c_msg_s_q));
	log(dec_CBSP_PDU(c_msg_s_q_compl));
	log(dec_CBSP_PDU(c_kill_compl));
}

import from SABP_Types all;
import from SABP_Templates all;
import from SABP_IEs all;
import from SABP_PDU_Descriptions all;

testcase TC_selftest_sabp() runs on test_CT {
	const octetstring c_write := '00000080930000080006000211120007000240c0000f0010000113f0030282ec0613f0030282ec070001400100000d0002012a000900020000000400010100000056029f01b4d90d064297d9ec37e8fe96b3c9a0303bdd68341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d168341a8d46a3d10012'O;

	log(dec_SABP_PDU(c_write));
	log(enc_SABP_PDU(dec_SABP_PDU(c_write)));

	var template (value) Service_Areas_List sa_list := {
		ts_SabpSai('62F224'O, '0023'O, '0042'O)
	};
	var template (value) SABP_PDU tx;

	tx := ts_SABP_Write(int2bit(1, 16), int2bit(1, 16), sa_list, 23, 42, '00000000'B, '01011010'B);
	log("Write: ", enc_SABP_PDU(valueof(tx)))

	var Service_Areas_List sa_list2 := { valueof(ts_SabpSai('62F224'O, '1000'O, '0042'O)) };
	for (var integer i := 0; i < 2500; i := i+1) {
		sa_list2 := sa_list2 & {valueof(ts_SabpSai('62F224'O, '2000'O, int2oct(i,2))) };
	}
	tx := ts_SABP_Write(int2bit(2, 16), int2bit(2, 16), sa_list2, 23, 42, '00000000'B, '01011010'B);
	log("Write: ", enc_SABP_PDU(valueof(tx)))

	tx := ts_SABP_Restart(sa_list);
	log("Restart: ", enc_SABP_PDU(valueof(tx)));
}

}