Harald Welte | 867243a | 2020-09-13 18:32:32 +0200 | [diff] [blame^] | 1 | /* NS Provider for NS/FR/E1 |
| 2 | * (C) 2020 Harald Welte <laforge@gnumonks.org> |
| 3 | * contributions by sysmocom - s.f.m.c. GmbH |
| 4 | * All rights reserved. |
| 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 NS_Provider_FR { |
| 13 | |
| 14 | import from NS_Emulation all; |
| 15 | import from NS_Types all; |
| 16 | |
| 17 | import from AF_PACKET_PortType all; |
| 18 | import from FrameRelay_Types all; |
| 19 | import from FrameRelay_Emulation all; |
| 20 | |
| 21 | |
| 22 | type component NS_Provider_FR_CT extends NS_Provider_CT, FR_Client_CT { |
| 23 | /* component reference to Frame Relay emulation */ |
| 24 | var FR_Emulation_CT vc_FREMU; |
| 25 | }; |
| 26 | |
| 27 | function main(NSConfiguration config) runs on NS_Provider_FR_CT system af_packet { |
| 28 | |
| 29 | /* start Frame Relay Emulation */ |
| 30 | vc_FREMU := FR_Emulation_CT.create(); |
| 31 | var Q933em_Config q933_cfg := valueof(ts_Q933em_Config(ats_is_user := not config.role_sgsn, bidirectional := false)); |
| 32 | map(vc_FREMU:FR, system:AF_PACKET) param (config.provider.fr.netdev); |
| 33 | vc_FREMU.start(FrameRelay_Emulation.main(q933_cfg)); |
| 34 | |
| 35 | /* connect ourselves to frame relay emulation */ |
| 36 | connect(self:FR, vc_FREMU:CLIENT); |
| 37 | connect(self:FR_PROC, vc_FREMU:PROC); |
| 38 | |
| 39 | /* register ourselves for the specified DLCI */ |
| 40 | f_fremu_register(config.provider.fr.dlci); |
| 41 | |
| 42 | /* transceive between user-facing port and FR socket */ |
| 43 | while (true) { |
| 44 | var FrameRelayFrame rx_fr; |
| 45 | var FRemu_Event rx_frevt; |
| 46 | var PDU_NS rx_pdu; |
| 47 | alt { |
| 48 | |
| 49 | [] FR.receive(FrameRelayFrame:?) -> value rx_fr { |
| 50 | NSE.send(dec_PDU_NS(rx_fr.payload)); |
| 51 | } |
| 52 | |
| 53 | [] FR.receive(FRemu_Event:?) -> value rx_frevt { |
| 54 | /* TODO: dispatch to user */ |
| 55 | } |
| 56 | [] NSE.receive(PDU_NS:?) -> value rx_pdu { |
| 57 | FR.send(ts_FR(config.provider.fr.dlci, enc_PDU_NS(rx_pdu), true)); |
| 58 | } |
| 59 | |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | } /* main */ |
| 64 | |
| 65 | |
| 66 | |
| 67 | } /* module */ |