blob: 1878f3ea2bcae0d18ad485ad0a5d6d9e81913e95 [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
Pau Espin Pedroldb247f82022-08-01 17:55:22 +020028/* Coordinate with test_CT: */
29type port BSC_ConnHdlr_Coord_PT message {
30 inout charstring;
31} with { extension "internal" };
32
Pau Espin Pedrol4ff118a2022-07-28 17:37:47 +020033/* this component represents a single subscriber connection */
34type component BSC_ConnHdlr extends CBSP_Adapter_CT {
35 var BSC_ConnHdlrPars g_pars;
Pau Espin Pedroldb247f82022-08-01 17:55:22 +020036 port BSC_ConnHdlr_Coord_PT COORD;
Pau Espin Pedrol4ff118a2022-07-28 17:37:47 +020037}
38
39type record BSC_ConnHdlrPars {
Pau Espin Pedroldb247f82022-08-01 17:55:22 +020040 charstring bsc_host,
Pau Espin Pedrol4ff118a2022-07-28 17:37:47 +020041 integer bsc_cbsp_port,
42 charstring cbc_host,
43 integer cbc_cbsp_port,
Pau Espin Pedroldb247f82022-08-01 17:55:22 +020044 boolean tcp_is_client,
Pau Espin Pedrol4ff118a2022-07-28 17:37:47 +020045 void_fn start_fn,
46 CBS_Message exp_cbs_msg optional,
Pau Espin Pedrol6dd5a0f2022-08-05 15:16:48 +020047 BSSMAP_FIELD_CellIdentificationList cell_list_success optional,
48 CBSP_FailureListItems tx_fail_list optional
Pau Espin Pedrol4ff118a2022-07-28 17:37:47 +020049};
50
51function f_BSC_ConnHdlr_main(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
52 g_pars := pars;
Pau Espin Pedroldb247f82022-08-01 17:55:22 +020053 if (g_pars.tcp_is_client) {
54 CBSP_Adapter.f_connect(g_pars.cbc_host, g_pars.cbc_cbsp_port,
55 g_pars.bsc_host, g_pars.bsc_cbsp_port);
56 } else {
57 CBSP_Adapter.f_bind(g_pars.bsc_host, g_pars.bsc_cbsp_port);
58 CBSP_Adapter.f_wait_client_connect();
59 }
Pau Espin Pedrol4ff118a2022-07-28 17:37:47 +020060
61 var BSSMAP_FIELD_CellIdentificationList cell_list := {
62 cIl_allInBSS := ''O
63 };
64 activate(as_cbsp_keepalive_ack(0));
65 activate(as_cbsp_restart(0));
66 f_cbsp_send(ts_CBSP_RESTART(cell_list, CBSP_BC_MSGT_CBS, CBSP_RI_DATA_LOST));
67 f_cbsp_send(ts_CBSP_RESTART(cell_list, CBSP_BC_MSGT_EMERG, CBSP_RI_DATA_LOST));
68 as_cbsp_reset(0);
Pau Espin Pedroldb247f82022-08-01 17:55:22 +020069 COORD.send(COORD_MSG_CONNECTED);
Pau Espin Pedrol4ff118a2022-07-28 17:37:47 +020070
71 g_pars.start_fn.apply();
72}
73
74altstep as_cbsp_reset(integer idx) runs on CBSP_Adapter_CT {
75 var CBSP_RecvFrom rf;
76 [] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], tr_CBSP_RESET)) -> value rf {
77 var CBSP_IE ie;
78 f_cbsp_find_ie(rf.msg, CBSP_IEI_CELL_LIST, ie);
79 CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx],
80 ts_CBSP_RESET_COMPL(ie.body.cell_list.cell_id)));
81 }
82}
83
84/* receive + acknowledge KEEP-ALIVE */
85altstep as_cbsp_keepalive_ack(integer idx) runs on CBSP_Adapter_CT {
86 [] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], tr_CBSP_KEEP_ALIVE)) {
87 CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx], ts_CBSP_KEEP_ALIVE_COMPL));
88 }
89}
90
91/* receive + ignore RESTART */
92altstep as_cbsp_restart(integer idx) runs on CBSP_Adapter_CT {
93 [] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], tr_CBSP_RESTART));
94}
95
96function f_cbsp_tx_write_compl(CBS_Message msg, integer idx := 0,
97 template (omit) BSSMAP_FIELD_CellIdentificationList tx_cell_list := omit,
98 template (omit) CBSP_IE_NumBcastComplList tx_compl_list := omit)
99runs on BSC_ConnHdlr {
100 var template (value) CBSP_PDU tx;
101 var template (value) BSSMAP_FIELD_CellIdentificationList tx_list;
102 if (istemplatekind(tx_cell_list, "omit")) {
103 /* use the "expected list" when confirming the write-replace */
104 tx_list := msg.cell_list;
105 } else {
106 /* use an user-provided different list of cells */
107 tx_list := valueof(tx_cell_list);
108 }
109 if (istemplatekind(tx_compl_list, "omit")) {
Pau Espin Pedrolad5d2db2022-08-03 14:02:02 +0200110 if (msg_id_is_etws(msg.msg_id)) {
111 tx := ts_CBSP_WRITE_EMERG_COMPL(msg.msg_id, msg.ser_nr, tx_list);
112 } else {
113 tx := ts_CBSP_WRITE_CBS_COMPL(msg.msg_id, msg.ser_nr, tx_list, msg.channel_ind);
114 }
Pau Espin Pedrol4ff118a2022-07-28 17:37:47 +0200115 } else {
Pau Espin Pedrolad5d2db2022-08-03 14:02:02 +0200116 if (msg_id_is_etws(msg.msg_id)) {
117 tx := ts_CBSP_REPLACE_EMERG_COMPL(msg.msg_id, msg.ser_nr, msg.old_ser_nr,
118 tx_list);
119 } else {
120 tx := ts_CBSP_REPLACE_CBS_COMPL(msg.msg_id, msg.ser_nr, msg.old_ser_nr,
121 valueof(tx_compl_list), tx_list,
122 msg.channel_ind);
123 }
Pau Espin Pedrol4ff118a2022-07-28 17:37:47 +0200124 }
125 CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx], tx));
126}
127
128function f_cbsp_tx_write_fail(CBS_Message msg, integer idx := 0,
129 template (omit) BSSMAP_FIELD_CellIdentificationList tx_cell_list := omit,
Pau Espin Pedrol6dd5a0f2022-08-05 15:16:48 +0200130 template (omit) CBSP_IE_NumBcastComplList tx_compl_list := omit,
Pau Espin Pedrol4ff118a2022-07-28 17:37:47 +0200131 template (omit) CBSP_FailureListItems tx_fail_list := omit)
132runs on BSC_ConnHdlr {
133 var template (value) CBSP_PDU tx;
134 tx := ts_CBSP_WRITE_CBS_FAIL(msg.msg_id, msg.ser_nr, valueof(tx_fail_list),
Pau Espin Pedrol6dd5a0f2022-08-05 15:16:48 +0200135 tx_compl_list, tx_cell_list, msg.channel_ind);
Pau Espin Pedrol4ff118a2022-07-28 17:37:47 +0200136 CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx], tx));
137}
138
139/* handle a CBSP-WRITE-REPLACE and respond to it with COMPLETE or FAILURE depending on arguments */
140function f_cbsp_handle_write(CBS_Message msg, integer idx := 0,
141 template (omit) BSSMAP_FIELD_CellIdentificationList tx_cell_list := omit,
142 template (omit) CBSP_FailureListItems tx_fail_list := omit,
143 template (omit) CBSP_IE_NumBcastComplList tx_compl_list := omit)
144runs on BSC_ConnHdlr {
145 var template CBSP_IEs content_ies := {};
146 var template (present) CBSP_PDU rx_templ;
147 var CBSP_RecvFrom rf;
Pau Espin Pedrolad5d2db2022-08-03 14:02:02 +0200148 if (msg_id_is_etws(msg.msg_id)) {
149 rx_templ := tr_CBSP_WRITE_EMERG(msg.msg_id, msg.ser_nr, msg.cell_list, 1,
150 hex2int('180'H) + (msg.msg_id - 4352),
151 msg.num_bcast_req, 0)
152 } else {
153 for (var integer i := 0; i < lengthof(msg.content); i := i+1) {
154 //content_ies[i] := tr_CbspMsgContent(msg.content[i].payload, msg.content[i].user_len);
155 content_ies[i] := tr_CbspMsgContent(?, ?);
156 }
157 rx_templ := tr_CBSP_WRITE_CBS(msg.msg_id, msg.ser_nr, msg.cell_list, msg.channel_ind,
158 msg.category, msg.rep_period, msg.num_bcast_req, msg.dcs,
159 content_ies);
Pau Espin Pedrol4ff118a2022-07-28 17:37:47 +0200160 }
Pau Espin Pedrol4ff118a2022-07-28 17:37:47 +0200161 alt {
162 [] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], rx_templ)) -> value rf {
163 var template (value) CBSP_PDU tx;
164 if (istemplatekind(tx_fail_list, "omit")) {
165 f_cbsp_tx_write_compl(msg, idx, tx_cell_list, tx_compl_list);
166 } else {
Pau Espin Pedrol6dd5a0f2022-08-05 15:16:48 +0200167 f_cbsp_tx_write_fail(msg, idx, tx_cell_list, tx_compl_list, tx_fail_list);
Pau Espin Pedrol4ff118a2022-07-28 17:37:47 +0200168 }
169 }
170 [] as_cbsp_keepalive_ack(idx) { repeat; }
171 [] CBSP[idx].receive {
172 setverdict(fail, "Received unexpected CBSP in index ", idx);
173 }
174 }
175}
176
177/* handle a CBSP-KILL and respond to it with COMPLETE or FAILURE depending on arguments */
178function f_cbsp_handle_kill(integer idx, uint16_t msg_id, uint16_t ser_nr,
179 template BSSMAP_FIELD_CellIdentificationList exp_list,
180 template (omit) BSSMAP_FIELD_CellIdentificationList tx_list,
181 template (omit) CBSP_FailureListItems tx_fail_list := omit,
182 template (omit) CBSP_IE_NumBcastComplList tx_compl_list := omit,
183 template (omit) uint8_t channel_ind := omit)
184runs on BSC_ConnHdlr {
185 var template (present) CBSP_PDU rx_templ;
186 var CBSP_RecvFrom rf;
187
188 rx_templ := tr_CBSP_KILL(msg_id, ser_nr, exp_list, channel_ind);
189 alt {
190 [] CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], rx_templ)) -> value rf {
191 var template (value) CBSP_PDU tx;
192 if (istemplatekind(tx_fail_list, "omit")) {
193 tx := ts_CBSP_KILL_COMPL(msg_id, ser_nr, tx_compl_list, tx_list, channel_ind);
194 } else {
195 tx := ts_CBSP_KILL_FAIL(msg_id, ser_nr, valueof(tx_fail_list), tx_compl_list,
196 tx_list, channel_ind);
197 }
198 CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx], tx));
199 }
200 [] as_cbsp_keepalive_ack(idx) { repeat; }
201 [] CBSP[idx].receive {
202 setverdict(fail, "Received unexpected CBSP in index ", idx);
203 }
204 }
205}
206
207}