blob: 1cb02dd720f33c1b4ccd499ca04ac6a4b327564c [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;
Harald Weltebd612cd2020-09-14 09:42:28 +020025
26 var boolean link_available := false;
27 var boolean pvc_active := false;
Harald Welte867243a2020-09-13 18:32:32 +020028};
29
Harald Welte90f19742020-11-06 19:34:40 +010030function main(NSVCConfiguration config, NSConfiguration nsconfig, charstring id) runs on NS_Provider_FR_CT system af_packet {
Harald Welte867243a2020-09-13 18:32:32 +020031
32 /* start Frame Relay Emulation */
Harald Welte847a77e2020-09-14 12:55:47 +020033 vc_FREMU := FR_Emulation_CT.create(id & "-FRemu");
Harald Welte90f19742020-11-06 19:34:40 +010034 var Q933em_Config q933_cfg := valueof(ts_Q933em_Config(ats_is_user := not nsconfig.role_sgsn, bidirectional := false));
Harald Welte847a77e2020-09-14 12:55:47 +020035 q933_cfg.T391 := 1.0;
Harald Welte867243a2020-09-13 18:32:32 +020036 map(vc_FREMU:FR, system:AF_PACKET) param (config.provider.fr.netdev);
37 vc_FREMU.start(FrameRelay_Emulation.main(q933_cfg));
38
39 /* connect ourselves to frame relay emulation */
40 connect(self:FR, vc_FREMU:CLIENT);
41 connect(self:FR_PROC, vc_FREMU:PROC);
42
43 /* register ourselves for the specified DLCI */
44 f_fremu_register(config.provider.fr.dlci);
45
46 /* transceive between user-facing port and FR socket */
47 while (true) {
48 var FrameRelayFrame rx_fr;
49 var FRemu_Event rx_frevt;
50 var PDU_NS rx_pdu;
51 alt {
52
53 [] FR.receive(FrameRelayFrame:?) -> value rx_fr {
54 NSE.send(dec_PDU_NS(rx_fr.payload));
55 }
56
Harald Weltebd612cd2020-09-14 09:42:28 +020057 [] FR.receive(FRemu_Event:{link_status:=FR_LINK_STS_AVAILABLE}) -> value rx_frevt {
58 if (link_available == false and pvc_active == true) {
59 NSE.send(NS_Provider_Evt:{link_status := NS_PROV_LINK_STATUS_UP});
60 }
61 link_available := true;
62 }
63 [] FR.receive(FRemu_Event:{link_status:=FR_LINK_STS_UNAVAILABLE}) -> value rx_frevt {
64 link_available := false;
65 NSE.send(NS_Provider_Evt:{link_status := NS_PROV_LINK_STATUS_DOWN});
66 }
67 [] FR.receive(tr_FRemu_PvcStatusAct(config.provider.fr.dlci, true)) -> value rx_frevt {
68 if (pvc_active == false and link_available == true) {
69 NSE.send(NS_Provider_Evt:{link_status := NS_PROV_LINK_STATUS_UP});
70 }
71 pvc_active := true;
72 }
73 [] FR.receive(tr_FRemu_PvcStatusAct(config.provider.fr.dlci, false)) -> value rx_frevt {
74 pvc_active := false;
75 NSE.send(NS_Provider_Evt:{link_status := NS_PROV_LINK_STATUS_DOWN});
76 }
Harald Welte867243a2020-09-13 18:32:32 +020077 [] FR.receive(FRemu_Event:?) -> value rx_frevt {
Harald Weltebd612cd2020-09-14 09:42:28 +020078 log("Unhandled FRemu_event: ", rx_frevt);
Harald Welte867243a2020-09-13 18:32:32 +020079 }
80 [] NSE.receive(PDU_NS:?) -> value rx_pdu {
81 FR.send(ts_FR(config.provider.fr.dlci, enc_PDU_NS(rx_pdu), true));
82 }
83
84 }
85 }
86
87} /* main */
88
89
90
91} /* module */