blob: 8dbee6a6a3620275834e1aeb3a281bf79243aee0 [file] [log] [blame]
Harald Weltecd451ef2019-05-06 17:20:44 +02001module CBSP_Adapter {
2
3/* CBSP Adapter layer, sitting on top of CBSP_CodecPort.
4 * test suites can 'inherit' in order to have a CBSP connection to the IUT which they're testing
5 *
6 * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
7 * All rights reserved.
8 *
9 * Released under the terms of GNU General Public License, Version 2 or
10 * (at your option) any later version.
11 */
12
13
14import from Osmocom_Types all;
15import from General_Types all;
16import from CBSP_Types all;
17import from CBSP_Templates all;
18import from CBSP_CodecPort all;
19import from CBSP_CodecPort_CtrlFunct all;
20import from IPL4asp_Types all;
21import from IPL4asp_PortType all;
22import from Socket_API_Definitions all;
23
24const integer NUM_CBSP := 3;
25
26type component CBSP_Adapter_CT {
27 /* down-facing port to CBSP Codec port */
28 port CBSP_CODEC_PT CBSP[NUM_CBSP];
29 var IPL4asp_Types.ConnectionId g_cbsp_conn_id[NUM_CBSP] := { -1, -1, -1 };
30}
31
32private function f_set_tcp_segmentation(integer idx) runs on CBSP_Adapter_CT {
33 /* Set function for dissecting the binary stream into packets */
34 var f_IPL4_getMsgLen vl_f := refers(f_IPL4_fixedMsgLen);
35 /* Offset: 1, size of length: 3, delta: 4, multiplier: 1, big-endian */
36 CBSP_CodecPort_CtrlFunct.f_IPL4_setGetMsgLen(CBSP[idx], g_cbsp_conn_id[idx], vl_f, {1, 3, 4, 1, 0});
37}
38
39function f_connect(charstring remote_host, IPL4asp_Types.PortNumber remote_port,
40 charstring local_host, IPL4asp_Types.PortNumber local_port, integer idx := 0)
41runs on CBSP_Adapter_CT {
42 var IPL4asp_Types.Result res;
43 map(self:CBSP[idx], system:CBSP);
44 res := CBSP_CodecPort_CtrlFunct.f_IPL4_connect(CBSP[idx], remote_host, remote_port,
45 local_host, local_port, 0, { tcp :={} });
46 if (not ispresent(res.connId)) {
47 setverdict(fail, "Could not connect to CBSP port, check your configuration");
48 mtc.stop;
49 }
50 g_cbsp_conn_id[idx] := res.connId;
51
52 f_set_tcp_segmentation(idx);
53}
54
55/* Function to use to bind to a local port as IPA server, accepting remote clients */
56function f_bind(charstring local_host, IPL4asp_Types.PortNumber local_port, integer idx := 0)
57runs on CBSP_Adapter_CT {
58 var IPL4asp_Types.Result res;
59 map(self:CBSP[idx], system:CBSP);
60 res := CBSP_CodecPort_CtrlFunct.f_IPL4_listen(CBSP[idx], local_host, local_port, { tcp:={} });
61 g_cbsp_conn_id[idx] := res.connId;
62
63 f_set_tcp_segmentation(idx);
64}
65
66function f_cbsp_send(template (value) CBSP_PDU pdu, integer idx := 0) runs on CBSP_Adapter_CT {
67 CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx], pdu));
68}
69
70function f_cbsp_exp(template CBSP_PDU exp, integer idx := 0) runs on CBSP_Adapter_CT return CBSP_PDU {
71 var CBSP_RecvFrom rf;
72 CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], exp)) -> value rf;
73 return rf.msg;
74}
75
76
77}