Neels Hofmeyr | 2d29274 | 2022-06-07 23:58:05 +0200 | [diff] [blame] | 1 | module CPF_ConnectionHandler { |
| 2 | |
| 3 | /* CPF Connection Handler of UPF_Tests in TTCN-3 |
| 4 | * (C) 2022 by sysmocom - s.m.f.c. GmbH <info@sysmocom.de> |
| 5 | * 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 | |
| 13 | import from Misc_Helpers all; |
| 14 | import from General_Types all; |
| 15 | import from Osmocom_Types all; |
| 16 | import from IPL4asp_Types all; |
| 17 | import from Native_Functions all; |
| 18 | |
| 19 | import from StatsD_Checker all; |
| 20 | |
| 21 | import from TELNETasp_PortType all; |
| 22 | import from Osmocom_VTY_Functions all; |
| 23 | |
| 24 | import from PFCP_Types all; |
| 25 | import 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). */ |
| 29 | type 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 | |
| 45 | function 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 | |
| 50 | function f_next_local_teid() runs on CPF_ConnHdlr return OCT4 { |
| 51 | g_next_local_teid_state := g_next_local_teid_state + 1; |
| 52 | return int2oct(g_next_local_teid_state, 4); |
| 53 | } |
| 54 | |
| 55 | function f_next_remote_teid() runs on CPF_ConnHdlr return OCT4 { |
| 56 | g_next_remote_teid_state := g_next_remote_teid_state + 1; |
| 57 | return int2oct(g_next_remote_teid_state, 4); |
| 58 | } |
| 59 | |
| 60 | function f_next_ue_addr() runs on CPF_ConnHdlr return charstring { |
| 61 | g_next_ue_addr_state := g_next_ue_addr_state + 1; |
| 62 | if (g_next_ue_addr_state > 254) { |
| 63 | g_next_ue_addr_state := 16; |
| 64 | } |
| 65 | return "192.168.44." & int2str(g_next_ue_addr_state); |
| 66 | } |
| 67 | |
| 68 | function f_CPF_ConnHdlr_init_vty() runs on CPF_ConnHdlr { |
| 69 | if (not g_vty_initialized) { |
| 70 | map(self:UPFVTY, system:UPFVTY); |
| 71 | f_vty_set_prompts(UPFVTY); |
| 72 | f_vty_transceive(UPFVTY, "enable"); |
| 73 | g_vty_initialized := true; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | private function f_CPF_ConnHdlr_init_pfcp(charstring id) runs on CPF_ConnHdlr { |
| 78 | id := id & "-PFCP"; |
| 79 | |
| 80 | g_recovery_timestamp := f_rnd_int(4294967295); |
| 81 | g_next_seid_state := (1 + f_rnd_int(65534)) * 65536; |
| 82 | g_next_local_teid_state := (1 + f_rnd_int(65534)) * 65536; |
| 83 | g_next_remote_teid_state := (1 + f_rnd_int(65534)) * 65536; |
| 84 | g_next_ue_addr_state := (1 + f_rnd_int(15)) * 16; |
| 85 | |
| 86 | var PFCP_Emulation_Cfg pfcp_cfg := { |
| 87 | pfcp_bind_ip := g_pars.local_addr, |
| 88 | pfcp_bind_port := g_pars.local_port, |
| 89 | pfcp_remote_ip := g_pars.remote_upf_addr, |
| 90 | pfcp_remote_port := g_pars.remote_upf_port, |
| 91 | role := CPF |
| 92 | }; |
| 93 | |
| 94 | vc_PFCP := PFCP_Emulation_CT.create(id) alive; |
| 95 | connect(self:PFCP, vc_PFCP:CLIENT); |
| 96 | vc_PFCP.start(PFCP_Emulation.main(pfcp_cfg)); |
| 97 | } |
| 98 | |
| 99 | /* initialize all parameters */ |
| 100 | function f_CPF_ConnHdlr_init(charstring id, TestHdlrParams pars) runs on CPF_ConnHdlr { |
| 101 | g_pars := valueof(pars); |
| 102 | f_CPF_ConnHdlr_init_pfcp(id); |
| 103 | f_CPF_ConnHdlr_init_vty(); |
| 104 | } |
| 105 | |
| 106 | type record TestHdlrParams { |
| 107 | charstring remote_upf_addr, |
| 108 | integer remote_upf_port, |
| 109 | charstring local_addr, |
| 110 | integer local_port, |
| 111 | Node_ID local_node_id |
| 112 | }; |
| 113 | |
| 114 | /* Note: Do not use valueof() to get a value of this template, use |
| 115 | * f_gen_test_hdlr_pars() instead in order to get a configuration. */ |
| 116 | template (value) TestHdlrParams t_def_TestHdlrPars := { |
| 117 | remote_upf_addr := "127.0.0.1", |
| 118 | remote_upf_port := 8805, |
| 119 | local_addr := "127.0.0.2", |
| 120 | local_port := 8805 |
| 121 | } |
| 122 | |
| 123 | } |