blob: 289be06e707c6e8b41695b7f7ab83141956fbc7b [file] [log] [blame]
Harald Welte619b2a62019-11-22 00:35:52 +01001module VPCD_Adapter {
2
3/* VPCD Adapter layer, sitting on top of VPCD_CodecPort.
4 * test suites can 'inherit' in order to have a VPCD 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
13import from VPCD_Types all;
14import from VPCD_CodecPort all;
15import from VPCD_CodecPort_CtrlFunct all;
16import from IPL4asp_Types all;
17import from IPL4asp_PortType all;
18import from Socket_API_Definitions all;
19
20modulepar {
21 integer mp_vpcd_port := 35963;
22 charstring mp_vpcd_host := "127.0.0.1";
23}
24
25type component VPCD_Adapter_CT {
26 port VPCD_CODEC_PT VPCD;
27 var integer g_vpcd_conn_id;
28};
29
30
31private function f_set_tcp_segmentation() runs on VPCD_Adapter_CT {
32 /* Set function for dissecting the binary stream into packets */
33 var f_IPL4_getMsgLen vl_f := refers(f_IPL4_fixedMsgLen);
34 /* Offset: 0, size of length: 2, delta: 0, multiplier: 1, big-endian: 0 */
35 VPCD_CodecPort_CtrlFunct.f_IPL4_setGetMsgLen(VPCD, g_vpcd_conn_id, vl_f, {0, 2, 2, 1, 0});
36}
37
38function f_connect(charstring remote_host := mp_vpcd_host, integer remote_port := mp_vpcd_port)
39runs on VPCD_Adapter_CT {
40 var IPL4asp_Types.Result res;
41 map(self:VPCD, system:VPCD);
42 res := VPCD_CodecPort_CtrlFunct.f_IPL4_connect(VPCD, remote_host, remote_port, "", 0, 0,
43 { tcp := {} });
44 if (not ispresent(res.connId)) {
45 setverdict(fail, "Could not connect to VPCD at ", remote_host, ":", remote_port,
46 ", check your configuration");
47 mtc.stop;
48 }
49 g_vpcd_conn_id := res.connId;
50 f_set_tcp_segmentation();
51}
52
53function f_bind(charstring local_host, IPL4asp_Types.PortNumber local_port)
54runs on VPCD_Adapter_CT {
55 var IPL4asp_Types.Result res;
56 map(self:VPCD, system:VPCD);
57 res := VPCD_CodecPort_CtrlFunct.f_IPL4_listen(VPCD, local_host, local_port, { tcp:={} });
58 g_vpcd_conn_id := res.connId;
59 f_set_tcp_segmentation();
60}
61
62function f_vpcd_send(template (value) VPCD_PDU pdu) runs on VPCD_Adapter_CT {
63 VPCD.send(ts_VPCD_Send(g_vpcd_conn_id, pdu));
64}
65
66function f_vpcd_exp(template VPCD_PDU exp) runs on VPCD_Adapter_CT return VPCD_PDU {
67 var VPCD_RecvFrom rf;
68 VPCD.receive(tr_VPCD_Recv(g_vpcd_conn_id, exp)) -> value rf;
69 return rf.msg;
70}
71
72
73}