summaryrefslogtreecommitdiffstats
path: root/library/NS_Provider_IPL4.ttcn
blob: 14149350b411d7edb2e0f919113c41a84c420bb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* NS Provider for NS/UDP/IP
 * (C) 2020 Harald Welte <laforge@gnumonks.org>
 * contributions by sysmocom - s.f.m.c. GmbH
 * All rights reserved.
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

module NS_Provider_IPL4 {

import from NS_Emulation all;
import from NS_Types all;

import from IPL4asp_Types all;
import from IPL4asp_PortType all;

type component NS_Provider_IPL4_CT extends NS_Provider_CT {
	/* down-facing port towards IPL4asp to IUT */
	port IPL4asp_PT IPL4;
	var integer g_conn_id := -1;
};

function main(NSConfiguration config) runs on NS_Provider_IPL4_CT {

	/* connect socket */
	map(self:IPL4, system:IPL4);
	var Result res := f_IPL4_connect(IPL4, config.provider.ip.remote_ip,
					 config.provider.ip.remote_udp_port,
					 config.provider.ip.local_ip,
					 config.provider.ip.local_udp_port, 0, { udp := {}});
	if (not ispresent(res.connId)) {
		setverdict(fail, "Could not connect NS UDP socket ", config.provider.ip);
		mtc.stop;
	}
	g_conn_id := res.connId;

	/* transceive beteween user-facing port and UDP socket */
	while (true) {
	var ASP_RecvFrom rx_rf;
	var PDU_NS rx_pdu;
	alt {

	[] IPL4.receive(ASP_RecvFrom:?) -> value rx_rf {
		NSE.send(dec_PDU_NS(rx_rf.msg));
		}

	[] IPL4.receive(ASP_ConnId_ReadyToRelease:?) {
		}

	[] IPL4.receive(ASP_Event:?) {
		}

	[] NSE.receive(PDU_NS:?) -> value rx_pdu {
		IPL4.send(ASP_Send:{connId := g_conn_id, proto := { udp := {} }, msg := enc_PDU_NS(rx_pdu)});
		}

	} /* alt */
	} /* while */

} /* main */



} /* module */