blob: 851e6c4f3b5273c3451eacfe66f119e14be6abfb [file] [log] [blame]
Harald Welte867243a2020-09-13 18:32:32 +02001/* 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
12module NS_Provider_FR {
13
14import from NS_Emulation all;
15import from NS_Types all;
16
17import from AF_PACKET_PortType all;
18import from FrameRelay_Types all;
19import from FrameRelay_Emulation all;
20
21
22type 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
27function 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 */