blob: b5945d3fcf8012bfad14de1a2e43582dccf33e2c [file] [log] [blame]
Neels Hofmeyr2d292742022-06-07 23:58:05 +02001module CPF_ConnectionHandler {
2
3/* CPF Connection Handler of UPF_Tests in TTCN-3
Vadim Yanitskiy47b32462023-05-18 18:58:40 +07004 * (C) 2022 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
Neels Hofmeyr2d292742022-06-07 23:58:05 +02005 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
12
13import from Misc_Helpers all;
14import from General_Types all;
15import from Osmocom_Types all;
16import from IPL4asp_Types all;
17import from Native_Functions all;
18
19import from StatsD_Checker all;
20
21import from TELNETasp_PortType all;
22import from Osmocom_VTY_Functions all;
23
24import from PFCP_Types all;
25import from PFCP_Emulation all;
26
27/* The system under test is a UPF (User Plane Function). This component represents a Control Plane Function, with a
28 * single association via PFCP to the UPF (User Plane Function). */
29type component CPF_ConnHdlr extends StatsD_ConnHdlr {
30 port PFCPEM_PT PFCP;
31 port TELNETasp_PT UPFVTY;
32
33 var PFCP_Emulation_CT vc_PFCP;
34
35 var TestHdlrParams g_pars;
36
37 var boolean g_vty_initialized := false;
38 var integer g_recovery_timestamp;
39 var integer g_next_seid_state;
40 var integer g_next_local_teid_state;
41 var integer g_next_remote_teid_state;
42 var integer g_next_ue_addr_state;
43}
44
45function f_next_seid() runs on CPF_ConnHdlr return OCT8 {
46 g_next_seid_state := g_next_seid_state + 1;
47 return int2oct(g_next_seid_state, 8);
48}
49
Neels Hofmeyr2d292742022-06-07 23:58:05 +020050function f_next_remote_teid() runs on CPF_ConnHdlr return OCT4 {
51 g_next_remote_teid_state := g_next_remote_teid_state + 1;
52 return int2oct(g_next_remote_teid_state, 4);
53}
54
55function f_next_ue_addr() runs on CPF_ConnHdlr return charstring {
56 g_next_ue_addr_state := g_next_ue_addr_state + 1;
57 if (g_next_ue_addr_state > 254) {
58 g_next_ue_addr_state := 16;
59 }
60 return "192.168.44." & int2str(g_next_ue_addr_state);
61}
62
63function f_CPF_ConnHdlr_init_vty() runs on CPF_ConnHdlr {
64 if (not g_vty_initialized) {
65 map(self:UPFVTY, system:UPFVTY);
66 f_vty_set_prompts(UPFVTY);
67 f_vty_transceive(UPFVTY, "enable");
68 g_vty_initialized := true;
69 }
70}
71
72private function f_CPF_ConnHdlr_init_pfcp(charstring id) runs on CPF_ConnHdlr {
73 id := id & "-PFCP";
74
75 g_recovery_timestamp := f_rnd_int(4294967295);
76 g_next_seid_state := (1 + f_rnd_int(65534)) * 65536;
77 g_next_local_teid_state := (1 + f_rnd_int(65534)) * 65536;
78 g_next_remote_teid_state := (1 + f_rnd_int(65534)) * 65536;
79 g_next_ue_addr_state := (1 + f_rnd_int(15)) * 16;
80
81 var PFCP_Emulation_Cfg pfcp_cfg := {
82 pfcp_bind_ip := g_pars.local_addr,
83 pfcp_bind_port := g_pars.local_port,
84 pfcp_remote_ip := g_pars.remote_upf_addr,
85 pfcp_remote_port := g_pars.remote_upf_port,
86 role := CPF
87 };
88
89 vc_PFCP := PFCP_Emulation_CT.create(id) alive;
90 connect(self:PFCP, vc_PFCP:CLIENT);
91 vc_PFCP.start(PFCP_Emulation.main(pfcp_cfg));
92}
93
94/* initialize all parameters */
95function f_CPF_ConnHdlr_init(charstring id, TestHdlrParams pars) runs on CPF_ConnHdlr {
96 g_pars := valueof(pars);
97 f_CPF_ConnHdlr_init_pfcp(id);
98 f_CPF_ConnHdlr_init_vty();
99}
100
101type record TestHdlrParams {
102 charstring remote_upf_addr,
103 integer remote_upf_port,
104 charstring local_addr,
105 integer local_port,
106 Node_ID local_node_id
107};
108
109/* Note: Do not use valueof() to get a value of this template, use
110 * f_gen_test_hdlr_pars() instead in order to get a configuration. */
111template (value) TestHdlrParams t_def_TestHdlrPars := {
112 remote_upf_addr := "127.0.0.1",
113 remote_upf_port := 8805,
114 local_addr := "127.0.0.2",
115 local_port := 8805
116}
117
118}