Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 1 | /* NS Provider for NS/UDP/IP |
| 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_IPL4 { |
| 13 | |
| 14 | import from NS_Emulation all; |
| 15 | import from NS_Types all; |
| 16 | |
| 17 | import from IPL4asp_Types all; |
| 18 | import from IPL4asp_PortType all; |
| 19 | |
| 20 | type component NS_Provider_IPL4_CT extends NS_Provider_CT { |
| 21 | /* down-facing port towards IPL4asp to IUT */ |
| 22 | port IPL4asp_PT IPL4; |
| 23 | var integer g_conn_id := -1; |
| 24 | }; |
| 25 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 26 | function main(NSVCConfiguration config, NSConfiguration nsconfig, charstring id) runs on NS_Provider_IPL4_CT { |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 27 | |
| 28 | /* connect socket */ |
Alexander Couzens | 3ee8268 | 2020-09-17 23:53:32 +0200 | [diff] [blame] | 29 | map(self:IPL4, system:IPL4); |
Harald Welte | 5e8573e | 2020-09-13 15:32:56 +0200 | [diff] [blame] | 30 | var Result res := f_IPL4_connect(IPL4, config.provider.ip.remote_ip, |
| 31 | config.provider.ip.remote_udp_port, |
| 32 | config.provider.ip.local_ip, |
| 33 | config.provider.ip.local_udp_port, 0, { udp := {}}); |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 34 | if (not ispresent(res.connId)) { |
Harald Welte | 5e8573e | 2020-09-13 15:32:56 +0200 | [diff] [blame] | 35 | setverdict(fail, "Could not connect NS UDP socket ", config.provider.ip); |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 36 | mtc.stop; |
| 37 | } |
| 38 | g_conn_id := res.connId; |
Harald Welte | bd612cd | 2020-09-14 09:42:28 +0200 | [diff] [blame] | 39 | NSE.send(NS_Provider_Evt:{link_status := NS_PROV_LINK_STATUS_UP}); |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 40 | |
Alexander Couzens | 6da7aaf | 2021-01-10 21:40:43 +0100 | [diff] [blame] | 41 | /* transceive between user-facing port and UDP socket */ |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 42 | while (true) { |
| 43 | var ASP_RecvFrom rx_rf; |
| 44 | var PDU_NS rx_pdu; |
| 45 | alt { |
| 46 | |
| 47 | [] IPL4.receive(ASP_RecvFrom:?) -> value rx_rf { |
| 48 | NSE.send(dec_PDU_NS(rx_rf.msg)); |
| 49 | } |
| 50 | |
| 51 | [] IPL4.receive(ASP_ConnId_ReadyToRelease:?) { |
| 52 | } |
| 53 | |
| 54 | [] IPL4.receive(ASP_Event:?) { |
| 55 | } |
| 56 | |
| 57 | [] NSE.receive(PDU_NS:?) -> value rx_pdu { |
| 58 | IPL4.send(ASP_Send:{connId := g_conn_id, proto := { udp := {} }, msg := enc_PDU_NS(rx_pdu)}); |
| 59 | } |
| 60 | |
| 61 | } /* alt */ |
| 62 | } /* while */ |
| 63 | |
| 64 | } /* main */ |
| 65 | |
| 66 | |
| 67 | |
| 68 | } /* module */ |