blob: ec86f01c0a855b7a8ff39b6bd479e7f2ae02d945 [file] [log] [blame]
Pau Espin Pedrol4ff118a2022-07-28 17:37:47 +02001/* BSC (CBSP) Connection Handler of CBC test suite in TTCN-3
2 * (C) 2022 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
3 * All rights reserved.
4 *
5 * Author: Pau Espin Pedrol <pespin@sysmocom.de>
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
13module BSC_ConnectionHandler {
14
15import from Osmocom_Types all;
16
17import from BSSAP_Types all;
18import from BSSMAP_Templates all;
19import from CBSP_Types all;
20import from CBSP_Templates all;
21import from CBSP_Adapter all;
22import from CBSP_CodecPort all;
23
24import from CBS_Message all;
25
26type function void_fn() runs on BSC_ConnHdlr;
27
28/* this component represents a single subscriber connection */
29type component BSC_ConnHdlr extends CBSP_Adapter_CT {
30 var BSC_ConnHdlrPars g_pars;
31}
32
33type record BSC_ConnHdlrPars {
34 integer bsc_cbsp_port,
35 charstring cbc_host,
36 integer cbc_cbsp_port,
37 void_fn start_fn,
38 CBS_Message exp_cbs_msg optional,
39 BSSMAP_FIELD_CellIdentificationList cell_list_success optional
40};
41
42function f_BSC_ConnHdlr_main(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
43 g_pars := pars;
44 CBSP_Adapter.f_connect(g_pars.cbc_host, g_pars.cbc_cbsp_port, "", g_pars.bsc_cbsp_port);
45
46 var BSSMAP_FIELD_CellIdentificationList cell_list := {
47 cIl_allInBSS := ''O
48 };
49 activate(as_cbsp_keepalive_ack(0));
50 activate(as_cbsp_restart(0));
51 f_cbsp_send(ts_CBSP_RESTART(cell_list, CBSP_BC_MSGT_CBS, CBSP_RI_DATA_LOST));
52 f_cbsp_send(ts_CBSP_RESTART(cell_list, CBSP_BC_MSGT_EMERG, CBSP_RI_DATA_LOST));
53 as_cbsp_reset(0);
54
55 g_pars.start_fn.apply();
56}
57
58altstep as_cbsp_reset(integer idx) runs on CBSP_Adapter_CT {
59 var CBSP_RecvFrom rf;
60 [] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], tr_CBSP_RESET)) -> value rf {
61 var CBSP_IE ie;
62 f_cbsp_find_ie(rf.msg, CBSP_IEI_CELL_LIST, ie);
63 CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx],
64 ts_CBSP_RESET_COMPL(ie.body.cell_list.cell_id)));
65 }
66}
67
68/* receive + acknowledge KEEP-ALIVE */
69altstep as_cbsp_keepalive_ack(integer idx) runs on CBSP_Adapter_CT {
70 [] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], tr_CBSP_KEEP_ALIVE)) {
71 CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx], ts_CBSP_KEEP_ALIVE_COMPL));
72 }
73}
74
75/* receive + ignore RESTART */
76altstep as_cbsp_restart(integer idx) runs on CBSP_Adapter_CT {
77 [] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], tr_CBSP_RESTART));
78}
79
80function f_cbsp_tx_write_compl(CBS_Message msg, integer idx := 0,
81 template (omit) BSSMAP_FIELD_CellIdentificationList tx_cell_list := omit,
82 template (omit) CBSP_IE_NumBcastComplList tx_compl_list := omit)
83runs on BSC_ConnHdlr {
84 var template (value) CBSP_PDU tx;
85 var template (value) BSSMAP_FIELD_CellIdentificationList tx_list;
86 if (istemplatekind(tx_cell_list, "omit")) {
87 /* use the "expected list" when confirming the write-replace */
88 tx_list := msg.cell_list;
89 } else {
90 /* use an user-provided different list of cells */
91 tx_list := valueof(tx_cell_list);
92 }
93 if (istemplatekind(tx_compl_list, "omit")) {
94 tx := ts_CBSP_WRITE_CBS_COMPL(msg.msg_id, msg.ser_nr, tx_list, msg.channel_ind);
95 } else {
96 tx := ts_CBSP_REPLACE_CBS_COMPL(msg.msg_id, msg.ser_nr, msg.old_ser_nr,
97 valueof(tx_compl_list), tx_list,
98 msg.channel_ind);
99 }
100 CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx], tx));
101}
102
103function f_cbsp_tx_write_fail(CBS_Message msg, integer idx := 0,
104 template (omit) BSSMAP_FIELD_CellIdentificationList tx_cell_list := omit,
105 template (omit) CBSP_FailureListItems tx_fail_list := omit)
106runs on BSC_ConnHdlr {
107 var template (value) CBSP_PDU tx;
108 tx := ts_CBSP_WRITE_CBS_FAIL(msg.msg_id, msg.ser_nr, valueof(tx_fail_list),
109 omit, tx_cell_list, msg.channel_ind);
110 CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx], tx));
111}
112
113/* handle a CBSP-WRITE-REPLACE and respond to it with COMPLETE or FAILURE depending on arguments */
114function f_cbsp_handle_write(CBS_Message msg, integer idx := 0,
115 template (omit) BSSMAP_FIELD_CellIdentificationList tx_cell_list := omit,
116 template (omit) CBSP_FailureListItems tx_fail_list := omit,
117 template (omit) CBSP_IE_NumBcastComplList tx_compl_list := omit)
118runs on BSC_ConnHdlr {
119 var template CBSP_IEs content_ies := {};
120 var template (present) CBSP_PDU rx_templ;
121 var CBSP_RecvFrom rf;
122 for (var integer i := 0; i < lengthof(msg.content); i := i+1) {
123 //content_ies[i] := tr_CbspMsgContent(msg.content[i].payload, msg.content[i].user_len);
124 content_ies[i] := tr_CbspMsgContent(?, ?);
125 }
126 rx_templ := tr_CBSP_WRITE_CBS(msg.msg_id, msg.ser_nr, msg.cell_list, msg.channel_ind,
127 msg.category, msg.rep_period, msg.num_bcast_req, msg.dcs,
128 content_ies);
129 alt {
130 [] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], rx_templ)) -> value rf {
131 var template (value) CBSP_PDU tx;
132 if (istemplatekind(tx_fail_list, "omit")) {
133 f_cbsp_tx_write_compl(msg, idx, tx_cell_list, tx_compl_list);
134 } else {
135 f_cbsp_tx_write_fail(msg, idx, tx_cell_list, tx_fail_list);
136 }
137 }
138 [] as_cbsp_keepalive_ack(idx) { repeat; }
139 [] CBSP[idx].receive {
140 setverdict(fail, "Received unexpected CBSP in index ", idx);
141 }
142 }
143}
144
145/* handle a CBSP-KILL and respond to it with COMPLETE or FAILURE depending on arguments */
146function f_cbsp_handle_kill(integer idx, uint16_t msg_id, uint16_t ser_nr,
147 template BSSMAP_FIELD_CellIdentificationList exp_list,
148 template (omit) BSSMAP_FIELD_CellIdentificationList tx_list,
149 template (omit) CBSP_FailureListItems tx_fail_list := omit,
150 template (omit) CBSP_IE_NumBcastComplList tx_compl_list := omit,
151 template (omit) uint8_t channel_ind := omit)
152runs on BSC_ConnHdlr {
153 var template (present) CBSP_PDU rx_templ;
154 var CBSP_RecvFrom rf;
155
156 rx_templ := tr_CBSP_KILL(msg_id, ser_nr, exp_list, channel_ind);
157 alt {
158 [] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], rx_templ)) -> value rf {
159 var template (value) CBSP_PDU tx;
160 if (istemplatekind(tx_fail_list, "omit")) {
161 tx := ts_CBSP_KILL_COMPL(msg_id, ser_nr, tx_compl_list, tx_list, channel_ind);
162 } else {
163 tx := ts_CBSP_KILL_FAIL(msg_id, ser_nr, valueof(tx_fail_list), tx_compl_list,
164 tx_list, channel_ind);
165 }
166 CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx], tx));
167 }
168 [] as_cbsp_keepalive_ack(idx) { repeat; }
169 [] CBSP[idx].receive {
170 setverdict(fail, "Received unexpected CBSP in index ", idx);
171 }
172 }
173}
174
175}