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; |
Harald Welte | bd612cd | 2020-09-14 09:42:28 +0200 | [diff] [blame] | 25 | |
| 26 | var boolean link_available := false; |
| 27 | var boolean pvc_active := false; |
Harald Welte | 867243a | 2020-09-13 18:32:32 +0200 | [diff] [blame] | 28 | }; |
| 29 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 30 | function main(NSVCConfiguration config, NSConfiguration nsconfig, charstring id) runs on NS_Provider_FR_CT system af_packet { |
Harald Welte | 867243a | 2020-09-13 18:32:32 +0200 | [diff] [blame] | 31 | |
| 32 | /* start Frame Relay Emulation */ |
Harald Welte | 847a77e | 2020-09-14 12:55:47 +0200 | [diff] [blame] | 33 | vc_FREMU := FR_Emulation_CT.create(id & "-FRemu"); |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 34 | var Q933em_Config q933_cfg := valueof(ts_Q933em_Config(ats_is_user := not nsconfig.role_sgsn, bidirectional := false)); |
Harald Welte | 847a77e | 2020-09-14 12:55:47 +0200 | [diff] [blame] | 35 | q933_cfg.T391 := 1.0; |
Harald Welte | 867243a | 2020-09-13 18:32:32 +0200 | [diff] [blame] | 36 | 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 Welte | bd612cd | 2020-09-14 09:42:28 +0200 | [diff] [blame] | 57 | [] 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; |
Harald Welte | c0c67ff | 2021-02-03 19:26:30 +0100 | [diff] [blame] | 65 | pvc_active := false; |
Harald Welte | bd612cd | 2020-09-14 09:42:28 +0200 | [diff] [blame] | 66 | NSE.send(NS_Provider_Evt:{link_status := NS_PROV_LINK_STATUS_DOWN}); |
| 67 | } |
| 68 | [] FR.receive(tr_FRemu_PvcStatusAct(config.provider.fr.dlci, true)) -> value rx_frevt { |
| 69 | if (pvc_active == false and link_available == true) { |
| 70 | NSE.send(NS_Provider_Evt:{link_status := NS_PROV_LINK_STATUS_UP}); |
| 71 | } |
| 72 | pvc_active := true; |
| 73 | } |
| 74 | [] FR.receive(tr_FRemu_PvcStatusAct(config.provider.fr.dlci, false)) -> value rx_frevt { |
| 75 | pvc_active := false; |
| 76 | NSE.send(NS_Provider_Evt:{link_status := NS_PROV_LINK_STATUS_DOWN}); |
| 77 | } |
Harald Welte | 867243a | 2020-09-13 18:32:32 +0200 | [diff] [blame] | 78 | [] FR.receive(FRemu_Event:?) -> value rx_frevt { |
Harald Welte | bd612cd | 2020-09-14 09:42:28 +0200 | [diff] [blame] | 79 | log("Unhandled FRemu_event: ", rx_frevt); |
Harald Welte | 867243a | 2020-09-13 18:32:32 +0200 | [diff] [blame] | 80 | } |
| 81 | [] NSE.receive(PDU_NS:?) -> value rx_pdu { |
| 82 | FR.send(ts_FR(config.provider.fr.dlci, enc_PDU_NS(rx_pdu), true)); |
| 83 | } |
| 84 | |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | } /* main */ |
| 89 | |
| 90 | |
| 91 | |
| 92 | } /* module */ |