Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame] | 1 | /* OsmoHNodeB Lower Layer Socket Interface codec port in TTCN-3 |
| 2 | * (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de> |
| 3 | * All rights reserved. |
| 4 | * Author: Pau Espin Pedrol <pespin@sysmocom.de> |
| 5 | * |
| 6 | * Released under the terms of GNU General Public License, Version 2 or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 10 | */ |
| 11 | |
| 12 | module HNBLLIF_CodecPort { |
| 13 | |
| 14 | import from Osmocom_Types all; |
| 15 | import from HNBLLIF_Types all; |
| 16 | import from UD_PortType all; |
| 17 | import from UD_Types all; |
| 18 | |
| 19 | type record HNBLLIF_send_data { |
| 20 | HNBLLIF_Message data, |
| 21 | integer id |
| 22 | }; |
| 23 | |
| 24 | private function HNBLLIF_to_UD(in HNBLLIF_send_data pin, out UD_send_data pout) { |
| 25 | pout.id := pin.id; |
| 26 | pout.data := enc_HNBLLIF_Message(pin.data); |
| 27 | } with { extension "prototype(fast)" }; |
| 28 | |
| 29 | private function UD_to_HNBLLIF(in UD_send_data pin, out HNBLLIF_send_data pout) { |
| 30 | pout.id := pin.id; |
| 31 | pout.data := dec_HNBLLIF_Message(pin.data); |
| 32 | } with { extension "prototype(fast)" }; |
| 33 | |
| 34 | type port HNBLLIF_CODEC_PT message { |
| 35 | out UD_close, UD_listen, UD_shutdown, UD_connect, HNBLLIF_send_data; |
| 36 | in UD_listen_result, UD_connect_result, UD_connected, HNBLLIF_send_data; |
| 37 | } with { extension "user UD_PT |
| 38 | out ( |
| 39 | UD_close -> UD_close:simple; |
| 40 | UD_listen -> UD_listen:simple; |
| 41 | UD_shutdown -> UD_shutdown:simple; |
| 42 | UD_connect -> UD_connect:simple; |
| 43 | HNBLLIF_send_data -> UD_send_data: function(HNBLLIF_to_UD) |
| 44 | ) |
| 45 | in ( |
| 46 | UD_listen_result -> UD_listen_result:simple; |
| 47 | UD_connect_result -> UD_connect_result:simple; |
| 48 | UD_send_data -> HNBLLIF_send_data: function(UD_to_HNBLLIF); |
| 49 | UD_connected -> UD_connected:simple |
| 50 | )" |
| 51 | }; |
| 52 | |
| 53 | template HNBLLIF_send_data t_SD_HNBLLIF(integer id, template HNBLLIF_Message pdu) := { |
| 54 | data := pdu, |
| 55 | id := id |
| 56 | } |
| 57 | template (value) HNBLLIF_send_data ts_SD_HNBLLIF(integer id, template (value) HNBLLIF_Message pdu) := { |
| 58 | data := pdu, |
| 59 | id := id |
| 60 | } |
| 61 | |
| 62 | function f_hnbllif_connect(HNBLLIF_CODEC_PT pt, charstring sock) return integer { |
| 63 | var UD_connect_result res; |
| 64 | timer T := 5.0; |
| 65 | |
| 66 | T.start; |
| 67 | pt.send(UD_connect:{sock, -1}); |
| 68 | alt { |
| 69 | [] pt.receive(UD_connect_result:?) -> value res { |
| 70 | if (ispresent(res.result) and ispresent(res.result.result_code) and |
| 71 | res.result.result_code == ERROR) { |
| 72 | if (ispresent(res.result.err)) { |
| 73 | setverdict(fail, "Error connecting to HNBLL socket ", sock, ": ", res.result.err); |
| 74 | } else { |
| 75 | setverdict(fail, "Error connecting to HNBLL socket ", sock); |
| 76 | } |
| 77 | mtc.stop; |
| 78 | } else { |
| 79 | return res.id; |
| 80 | } |
| 81 | } |
| 82 | [] T.timeout { |
| 83 | setverdict(fail, "Timeout connecting to HNBLL socket ", sock); |
| 84 | mtc.stop; |
| 85 | } |
| 86 | } |
| 87 | return -23; |
| 88 | } |
| 89 | |
| 90 | function f_hnbllif_close(HNBLLIF_CODEC_PT pt, integer id) |
| 91 | { |
| 92 | pt.send(UD_close:{id := id}); |
| 93 | } |
| 94 | |
| 95 | } |