blob: 9d72075bbb58493b87a693aa08c52c7dfde0f9c6 [file] [log] [blame]
Harald Welte013d65a2020-09-13 14:41:31 +02001/* 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
12module NS_Provider_IPL4 {
13
14import from NS_Emulation all;
15import from NS_Types all;
16
17import from IPL4asp_Types all;
18import from IPL4asp_PortType all;
19
20type 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 Welte90f19742020-11-06 19:34:40 +010026function main(NSVCConfiguration config, NSConfiguration nsconfig, charstring id) runs on NS_Provider_IPL4_CT {
Harald Welte013d65a2020-09-13 14:41:31 +020027
28 /* connect socket */
Alexander Couzens3ee82682020-09-17 23:53:32 +020029 map(self:IPL4, system:IPL4);
Harald Welte5e8573e2020-09-13 15:32:56 +020030 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 Welte013d65a2020-09-13 14:41:31 +020034 if (not ispresent(res.connId)) {
Harald Welte5e8573e2020-09-13 15:32:56 +020035 setverdict(fail, "Could not connect NS UDP socket ", config.provider.ip);
Harald Welte013d65a2020-09-13 14:41:31 +020036 mtc.stop;
37 }
38 g_conn_id := res.connId;
Harald Weltebd612cd2020-09-14 09:42:28 +020039 NSE.send(NS_Provider_Evt:{link_status := NS_PROV_LINK_STATUS_UP});
Harald Welte013d65a2020-09-13 14:41:31 +020040
Alexander Couzens6da7aaf2021-01-10 21:40:43 +010041 /* transceive between user-facing port and UDP socket */
Harald Welte013d65a2020-09-13 14:41:31 +020042 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 */