blob: 8ab8caaca7edb112f5440485dd44665e67446a5f [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 */
Alexander Couzens3ee82682020-09-17 23:53:32 +020029 map(self:IPL4, system:IPL4);
Harald Welte013d65a2020-09-13 14:41:31 +020030 var Result res := f_IPL4_connect(IPL4, config.remote_ip, config.remote_udp_port, config.local_ip,
31 config.local_udp_port, 0, { udp := {}});
32 if (not ispresent(res.connId)) {
33 setverdict(fail, "Could not connect NS UDP socket from " &
34 config.local_ip & ":" & int2str(config.local_udp_port) &
35 " to " & config.remote_ip & ":" & int2str(config.remote_udp_port));
36 mtc.stop;
37 }
38 g_conn_id := res.connId;
39
40 /* transceive beteween user-facing port and UDP socket */
41 while (true) {
42 var ASP_RecvFrom rx_rf;
43 var PDU_NS rx_pdu;
44 alt {
45
46 [] IPL4.receive(ASP_RecvFrom:?) -> value rx_rf {
47 NSE.send(dec_PDU_NS(rx_rf.msg));
48 }
49
50 [] IPL4.receive(ASP_ConnId_ReadyToRelease:?) {
51 }
52
53 [] IPL4.receive(ASP_Event:?) {
54 }
55
56 [] NSE.receive(PDU_NS:?) -> value rx_pdu {
57 IPL4.send(ASP_Send:{connId := g_conn_id, proto := { udp := {} }, msg := enc_PDU_NS(rx_pdu)});
58 }
59
60 } /* alt */
61 } /* while */
62
63} /* main */
64
65
66
67} /* module */