aboutsummaryrefslogtreecommitdiffstats
path: root/upf/CPF_ConnectionHandler.ttcn
blob: b5945d3fcf8012bfad14de1a2e43582dccf33e2c (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
module CPF_ConnectionHandler {

/* CPF Connection Handler of UPF_Tests in TTCN-3
 * (C) 2022 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
 * 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
 */

import from Misc_Helpers all;
import from General_Types all;
import from Osmocom_Types all;
import from IPL4asp_Types all;
import from Native_Functions all;

import from StatsD_Checker all;

import from TELNETasp_PortType all;
import from Osmocom_VTY_Functions all;

import from PFCP_Types all;
import from PFCP_Emulation all;

/* The system under test is a UPF (User Plane Function).  This component represents a Control Plane Function, with a
 * single association via PFCP to the UPF (User Plane Function). */
type component CPF_ConnHdlr extends StatsD_ConnHdlr {
	port PFCPEM_PT PFCP;
	port TELNETasp_PT UPFVTY;

	var PFCP_Emulation_CT vc_PFCP;

	var TestHdlrParams g_pars;

	var boolean g_vty_initialized := false;
	var integer g_recovery_timestamp;
	var integer g_next_seid_state;
	var integer g_next_local_teid_state;
	var integer g_next_remote_teid_state;
	var integer g_next_ue_addr_state;
}

function f_next_seid() runs on CPF_ConnHdlr return OCT8 {
	g_next_seid_state := g_next_seid_state + 1;
	return int2oct(g_next_seid_state, 8);
}

function f_next_remote_teid() runs on CPF_ConnHdlr return OCT4 {
	g_next_remote_teid_state := g_next_remote_teid_state + 1;
	return int2oct(g_next_remote_teid_state, 4);
}

function f_next_ue_addr() runs on CPF_ConnHdlr return charstring {
	g_next_ue_addr_state := g_next_ue_addr_state + 1;
	if (g_next_ue_addr_state > 254) {
		g_next_ue_addr_state := 16;
	}
	return "192.168.44." & int2str(g_next_ue_addr_state);
}

function f_CPF_ConnHdlr_init_vty() runs on CPF_ConnHdlr {
	if (not g_vty_initialized) {
		map(self:UPFVTY, system:UPFVTY);
		f_vty_set_prompts(UPFVTY);
		f_vty_transceive(UPFVTY, "enable");
		g_vty_initialized := true;
	}
}

private function f_CPF_ConnHdlr_init_pfcp(charstring id) runs on CPF_ConnHdlr {
	id := id & "-PFCP";

	g_recovery_timestamp := f_rnd_int(4294967295);
	g_next_seid_state := (1 + f_rnd_int(65534)) * 65536;
	g_next_local_teid_state := (1 + f_rnd_int(65534)) * 65536;
	g_next_remote_teid_state := (1 + f_rnd_int(65534)) * 65536;
	g_next_ue_addr_state := (1 + f_rnd_int(15)) * 16;

	var PFCP_Emulation_Cfg pfcp_cfg := {
		pfcp_bind_ip := g_pars.local_addr,
		pfcp_bind_port := g_pars.local_port,
		pfcp_remote_ip := g_pars.remote_upf_addr,
		pfcp_remote_port := g_pars.remote_upf_port,
		role := CPF
	};

	vc_PFCP := PFCP_Emulation_CT.create(id) alive;
	connect(self:PFCP, vc_PFCP:CLIENT);
	vc_PFCP.start(PFCP_Emulation.main(pfcp_cfg));
}

/* initialize all parameters */
function f_CPF_ConnHdlr_init(charstring id, TestHdlrParams pars) runs on CPF_ConnHdlr {
	g_pars := valueof(pars);
	f_CPF_ConnHdlr_init_pfcp(id);
	f_CPF_ConnHdlr_init_vty();
}

type record TestHdlrParams {
	charstring remote_upf_addr,
	integer remote_upf_port,
	charstring local_addr,
	integer local_port,
	Node_ID local_node_id
};

/* Note: Do not use valueof() to get a value of this template, use
 * f_gen_test_hdlr_pars() instead in order to get a configuration. */
template (value) TestHdlrParams t_def_TestHdlrPars := {
	remote_upf_addr := "127.0.0.1",
	remote_upf_port := 8805,
	local_addr := "127.0.0.2",
	local_port := 8805
}

}