Harald Welte | 7f26f55 | 2018-02-23 09:38:15 +0100 | [diff] [blame] | 1 | module TRXC_CodecPort { |
| 2 | |
| 3 | import from IPL4asp_PortType all; |
| 4 | import from IPL4asp_Types all; |
| 5 | import from TRXC_Types all; |
| 6 | |
| 7 | type record TRXC_RecvFrom { |
| 8 | ConnectionId connId, |
| 9 | HostName remName, |
| 10 | PortNumber remPort, |
| 11 | HostName locName, |
| 12 | PortNumber locPort, |
| 13 | TrxcMessage msg |
| 14 | } |
| 15 | |
Harald Welte | ef3e1c9 | 2018-02-28 23:40:14 +0100 | [diff] [blame] | 16 | template TRXC_RecvFrom tr_TRXC_RecvFrom(template ConnectionId cid, template TrxcMessage msg) := { |
| 17 | connId := cid, |
Harald Welte | 7f26f55 | 2018-02-23 09:38:15 +0100 | [diff] [blame] | 18 | remName := ?, |
| 19 | remPort := ?, |
| 20 | locName := ?, |
| 21 | locPort := ?, |
| 22 | msg := msg |
| 23 | } |
| 24 | |
| 25 | type record TRXC_Send { |
| 26 | ConnectionId connId, |
| 27 | TrxcMessage msg |
| 28 | } |
| 29 | |
| 30 | private 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 | |
| 39 | private 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 | |
| 45 | type 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 | |
| 57 | template (value) TRXC_Send ts_TRXC_Send(ConnectionId cid, template (value) TrxcMessage msg) := { |
| 58 | connId := cid, |
| 59 | msg := msg |
| 60 | } |
| 61 | |
Harald Welte | ef3e1c9 | 2018-02-28 23:40:14 +0100 | [diff] [blame] | 62 | function f_TRXC_transceive(TRXC_CODEC_PT pt, ConnectionId conn_id, TrxcMessage tx, |
| 63 | template TrxcMessage tr := ?) return TrxcMessage { |
| 64 | var TRXC_RecvFrom rf; |
| 65 | timer T := 3.0; |
| 66 | /* build better default template */ |
| 67 | if (istemplatekind(tr, "?")) { |
| 68 | tr := { |
| 69 | rsp := { |
| 70 | verb := tx.cmd.verb, |
| 71 | status := ?, |
| 72 | params := * |
| 73 | } |
| 74 | }; |
| 75 | } |
| 76 | pt.send(ts_TRXC_Send(conn_id, tx)); |
| 77 | T.start; |
| 78 | alt { |
| 79 | [] pt.receive(tr_TRXC_RecvFrom(conn_id, tr)) -> value rf { |
| 80 | return rf.msg; |
| 81 | } |
| 82 | [] T.timeout { |
| 83 | setverdict(fail, "Timeout waiting for ", tr, " on ", pt); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 84 | mtc.stop; |
Harald Welte | ef3e1c9 | 2018-02-28 23:40:14 +0100 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | return rf.msg; |
| 88 | } |
| 89 | |
Harald Welte | 7f26f55 | 2018-02-23 09:38:15 +0100 | [diff] [blame] | 90 | } |