blob: 5540d83b6a961c1416ee108a3a078ca13c176e48 [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
26function main(NSConfiguration config) runs on NS_Provider_IPL4_CT {
27
28 /* connect socket */
29 var Result res := f_IPL4_connect(IPL4, config.remote_ip, config.remote_udp_port, config.local_ip,
30 config.local_udp_port, 0, { udp := {}});
31 if (not ispresent(res.connId)) {
32 setverdict(fail, "Could not connect NS UDP socket from " &
33 config.local_ip & ":" & int2str(config.local_udp_port) &
34 " to " & config.remote_ip & ":" & int2str(config.remote_udp_port));
35 mtc.stop;
36 }
37 g_conn_id := res.connId;
38
39 /* transceive beteween user-facing port and UDP socket */
40 while (true) {
41 var ASP_RecvFrom rx_rf;
42 var PDU_NS rx_pdu;
43 alt {
44
45 [] IPL4.receive(ASP_RecvFrom:?) -> value rx_rf {
46 NSE.send(dec_PDU_NS(rx_rf.msg));
47 }
48
49 [] IPL4.receive(ASP_ConnId_ReadyToRelease:?) {
50 }
51
52 [] IPL4.receive(ASP_Event:?) {
53 }
54
55 [] NSE.receive(PDU_NS:?) -> value rx_pdu {
56 IPL4.send(ASP_Send:{connId := g_conn_id, proto := { udp := {} }, msg := enc_PDU_NS(rx_pdu)});
57 }
58
59 } /* alt */
60 } /* while */
61
62} /* main */
63
64
65
66} /* module */