blob: bb2193fda95ee73da486b6813af6bbbabe53d5cb [file] [log] [blame]
Harald Welte7f26f552018-02-23 09:38:15 +01001module TRXC_CodecPort {
2
3import from IPL4asp_PortType all;
4import from IPL4asp_Types all;
5import from TRXC_Types all;
6
7type record TRXC_RecvFrom {
8 ConnectionId connId,
9 HostName remName,
10 PortNumber remPort,
11 HostName locName,
12 PortNumber locPort,
13 TrxcMessage msg
14}
15
Harald Welteef3e1c92018-02-28 23:40:14 +010016template TRXC_RecvFrom tr_TRXC_RecvFrom(template ConnectionId cid, template TrxcMessage msg) := {
17 connId := cid,
Harald Welte7f26f552018-02-23 09:38:15 +010018 remName := ?,
19 remPort := ?,
20 locName := ?,
21 locPort := ?,
22 msg := msg
23}
24
25type record TRXC_Send {
26 ConnectionId connId,
27 TrxcMessage msg
28}
29
30private function IPL4_to_TRXC_RecvFrom(in ASP_RecvFrom pin, out TRXC_RecvFrom pout) {
31 pout.connId := pin.connId;
32 pout.remName := pin.remName;
33 pout.remPort := pin.remPort;
34 pout.locName := pin.locName;
35 pout.locPort := pin.locPort;
36 pout.msg := dec_TrxcMessage(oct2char(pin.msg));
37} with { extension "prototype(fast)" };
38
39private function TRXC_to_IPL4_Send(in TRXC_Send pin, out ASP_Send pout) {
40 pout.connId := pin.connId;
41 pout.proto := { udp := {} };
42 pout.msg := char2oct(enc_TrxcMessage(pin.msg));
43} with { extension "prototype(fast)" };
44
45type port TRXC_CODEC_PT message {
46 out TRXC_Send;
47 in TRXC_RecvFrom,
48 ASP_ConnId_ReadyToRelease,
49 ASP_Event;
50} with { extension "user IPL4asp_PT
51 out(TRXC_Send -> ASP_Send: function(TRXC_to_IPL4_Send))
52 in(ASP_RecvFrom -> TRXC_RecvFrom: function(IPL4_to_TRXC_RecvFrom);
53 ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple;
54 ASP_Event -> ASP_Event: simple)"
55}
56
57template (value) TRXC_Send ts_TRXC_Send(ConnectionId cid, template (value) TrxcMessage msg) := {
58 connId := cid,
59 msg := msg
60}
61
Vadim Yanitskiy418066a2021-10-03 14:04:17 +060062function f_TRXC_transceive(TRXC_CODEC_PT pt, ConnectionId conn_id,
63 template (value) TrxcMessage tx,
Harald Welteef3e1c92018-02-28 23:40:14 +010064 template TrxcMessage tr := ?) return TrxcMessage {
65 var TRXC_RecvFrom rf;
66 timer T := 3.0;
67 /* build better default template */
68 if (istemplatekind(tr, "?")) {
69 tr := {
70 rsp := {
71 verb := tx.cmd.verb,
72 status := ?,
73 params := *
74 }
75 };
76 }
77 pt.send(ts_TRXC_Send(conn_id, tx));
78 T.start;
79 alt {
80 [] pt.receive(tr_TRXC_RecvFrom(conn_id, tr)) -> value rf {
81 return rf.msg;
82 }
83 [] T.timeout {
84 setverdict(fail, "Timeout waiting for ", tr, " on ", pt);
Daniel Willmanne4ff5372018-07-05 17:35:03 +020085 mtc.stop;
Harald Welteef3e1c92018-02-28 23:40:14 +010086 }
87 }
88 return rf.msg;
89}
90
Harald Welte7f26f552018-02-23 09:38:15 +010091}