Pau Espin Pedrol | 7c13cb7 | 2022-06-16 19:03:44 +0200 | [diff] [blame^] | 1 | module SBC_AP_Adapter { |
| 2 | |
| 3 | /* SBC_AP Adapter layer, sitting on top of SBC_AP_CodecPort. |
| 4 | * test suites can 'inherit' in order to have a SBC_AP connection to the IUT which they're testing |
| 5 | * |
| 6 | * (C) 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 | |
| 14 | import from Osmocom_Types all; |
| 15 | import from General_Types all; |
| 16 | import from SBC_AP_Types all; |
| 17 | import from SBC_AP_PDU_Descriptions all; |
| 18 | import from SBC_AP_Templates all; |
| 19 | import from SBC_AP_CodecPort all; |
| 20 | import from SBC_AP_CodecPort_CtrlFunct all; |
| 21 | import from IPL4asp_Types all; |
| 22 | import from IPL4asp_PortType all; |
| 23 | import from Socket_API_Definitions all; |
| 24 | import from Misc_Helpers all; |
| 25 | |
| 26 | |
| 27 | const integer SBC_AP_HDR_LEN := 3; |
| 28 | |
| 29 | const integer NUM_SBC_AP := 3; |
| 30 | |
| 31 | type component SBC_AP_Adapter_CT { |
| 32 | /* down-facing port to SBC_AP Codec port */ |
| 33 | port SBC_AP_CODEC_PT SBC_AP[NUM_SBC_AP]; |
| 34 | var IPL4asp_Types.ConnectionId g_SBC_AP_conn_id[NUM_SBC_AP] := { -1, -1, -1 }; |
| 35 | } |
| 36 | |
| 37 | private template Socket_API_Definitions.PortEvent tr_SctpAssocChange_COMM_UP(IPL4asp_Types.ConnectionId id) := { |
| 38 | sctpEvent := { |
| 39 | sctpAssocChange := { |
| 40 | clientId := id, |
| 41 | proto := { |
| 42 | sctp := ? |
| 43 | }, |
| 44 | sac_state := SCTP_COMM_UP |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | function f_connect(charstring remote_host, IPL4asp_Types.PortNumber remote_port, |
| 50 | charstring local_host, IPL4asp_Types.PortNumber local_port, integer idx := 0) |
| 51 | runs on SBC_AP_Adapter_CT { |
| 52 | var IPL4asp_Types.Result res; |
| 53 | map(self:SBC_AP[idx], system:SBC_AP); |
| 54 | res := SBC_AP_CodecPort_CtrlFunct.f_IPL4_connect(SBC_AP[idx], remote_host, remote_port, |
| 55 | local_host, local_port, 0, { sctp := valueof(ts_SBC_AP_SctpTuple) }); |
| 56 | if (not ispresent(res.connId)) { |
| 57 | setverdict(fail, "Could not connect to SBC_AP port, check your configuration"); |
| 58 | mtc.stop; |
| 59 | } |
| 60 | g_SBC_AP_conn_id[idx] := res.connId; |
| 61 | timer Tcommup := 10.0; |
| 62 | Tcommup.start; |
| 63 | alt { |
| 64 | [] SBC_AP[idx].receive(tr_SctpAssocChange_COMM_UP(g_SBC_AP_conn_id[idx])) {} |
| 65 | [] Tcommup.timeout { |
| 66 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting SCTP_COMM_UP"); |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /* Function to use to bind to a local port as IPA server, accepting remote clients */ |
| 72 | function f_bind(charstring local_host, IPL4asp_Types.PortNumber local_port, integer idx := 0) |
| 73 | runs on SBC_AP_Adapter_CT { |
| 74 | var IPL4asp_Types.Result res; |
| 75 | map(self:SBC_AP[idx], system:SBC_AP); |
| 76 | res := SBC_AP_CodecPort_CtrlFunct.f_IPL4_listen(SBC_AP[idx], local_host, local_port, { sctp := valueof(ts_SBC_AP_SctpTuple) }); |
| 77 | g_SBC_AP_conn_id[idx] := res.connId; |
| 78 | } |
| 79 | |
| 80 | function f_SBC_AP_send(template (value) SBC_AP_PDU pdu, integer idx := 0) runs on SBC_AP_Adapter_CT { |
| 81 | SBC_AP[idx].send(ts_SBC_AP_Send(g_SBC_AP_conn_id[idx], pdu)); |
| 82 | } |
| 83 | |
| 84 | function f_SBC_AP_exp(template SBC_AP_PDU exp, integer idx := 0) runs on SBC_AP_Adapter_CT return SBC_AP_PDU { |
| 85 | var SBC_AP_RecvFrom rf; |
| 86 | SBC_AP[idx].receive(tr_SBC_AP_Recv(g_SBC_AP_conn_id[idx], exp)) -> value rf; |
| 87 | return rf.msg; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | } |