open5gs/src/upf/pfcp-path.c

329 lines
8.5 KiB
C
Raw Normal View History

2020-04-26 19:36:05 +00:00
/*
* Copyright (C) 2019 by Sukchan Lee <acetcom@gmail.com>
2020-04-26 19:36:05 +00:00
*
* This file is part of Open5GS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "context.h"
#include "pfcp-path.h"
#include "n4-build.h"
2020-05-14 17:38:26 +00:00
static void pfcp_node_fsm_init(ogs_pfcp_node_t *node, bool try_to_assoicate)
{
upf_event_t e;
ogs_assert(node);
2020-06-22 03:07:14 +00:00
memset(&e, 0, sizeof(e));
2020-05-14 17:38:26 +00:00
e.pfcp_node = node;
if (try_to_assoicate == true) {
node->t_association = ogs_timer_add(ogs_app()->timer_mgr,
2020-05-14 17:38:26 +00:00
upf_timer_association, node);
ogs_assert(node->t_association);
}
ogs_fsm_init(&node->sm, upf_pfcp_state_initial, upf_pfcp_state_final, &e);
2020-05-14 17:38:26 +00:00
}
static void pfcp_node_fsm_fini(ogs_pfcp_node_t *node)
{
upf_event_t e;
2020-06-22 03:07:14 +00:00
ogs_assert(node);
memset(&e, 0, sizeof(e));
2020-05-14 17:38:26 +00:00
e.pfcp_node = node;
ogs_fsm_fini(&node->sm, &e);
if (node->t_association)
ogs_timer_delete(node->t_association);
}
2020-04-26 19:36:05 +00:00
static void pfcp_recv_cb(short when, ogs_socket_t fd, void *data)
{
int rv;
ssize_t size;
upf_event_t *e = NULL;
ogs_pkbuf_t *pkbuf = NULL;
ogs_sockaddr_t from;
ogs_pfcp_node_t *node = NULL;
ogs_pfcp_header_t *h = NULL;
ogs_assert(fd != INVALID_SOCKET);
pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN);
ogs_assert(pkbuf);
2020-04-26 19:36:05 +00:00
ogs_pkbuf_put(pkbuf, OGS_MAX_SDU_LEN);
size = ogs_recvfrom(fd, pkbuf->data, pkbuf->len, 0, &from);
if (size <= 0) {
ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno,
"ogs_recvfrom() failed");
ogs_pkbuf_free(pkbuf);
return;
}
ogs_pkbuf_trim(pkbuf, size);
h = (ogs_pfcp_header_t *)pkbuf->data;
if (h->version != OGS_PFCP_VERSION) {
2020-04-26 19:36:05 +00:00
ogs_pfcp_header_t rsp;
ogs_error("Not supported version[%d]", h->version);
memset(&rsp, 0, sizeof rsp);
rsp.flags = (OGS_PFCP_VERSION << 5);
rsp.type = OGS_PFCP_VERSION_NOT_SUPPORTED_RESPONSE_TYPE;
rsp.length = htobe16(4);
rsp.sqn_only = h->sqn_only;
if (ogs_sendto(fd, &rsp, 8, 0, &from) < 0) {
ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno,
"ogs_sendto() failed");
}
2020-04-26 19:36:05 +00:00
ogs_pkbuf_free(pkbuf);
return;
}
e = upf_event_new(UPF_EVT_N4_MESSAGE);
2020-05-14 17:38:26 +00:00
ogs_assert(e);
2021-03-15 01:01:55 +00:00
node = ogs_pfcp_node_find(&ogs_pfcp_self()->pfcp_peer_list, &from);
2020-04-26 19:36:05 +00:00
if (!node) {
2021-03-15 01:01:55 +00:00
node = ogs_pfcp_node_add(&ogs_pfcp_self()->pfcp_peer_list, &from);
if (!node) {
ogs_error("No memory: ogs_pfcp_node_add() failed");
ogs_pkbuf_free(e->pkbuf);
ogs_event_free(e);
return;
}
2020-05-14 17:38:26 +00:00
2020-04-26 19:36:05 +00:00
node->sock = data;
2020-05-14 17:38:26 +00:00
pfcp_node_fsm_init(node, false);
2020-04-26 19:36:05 +00:00
}
e->pfcp_node = node;
e->pkbuf = pkbuf;
rv = ogs_queue_push(ogs_app()->queue, e);
2020-04-26 19:36:05 +00:00
if (rv != OGS_OK) {
ogs_error("ogs_queue_push() failed:%d", (int)rv);
2020-04-26 19:36:05 +00:00
ogs_pkbuf_free(e->pkbuf);
upf_event_free(e);
}
}
int upf_pfcp_open(void)
{
ogs_socknode_t *node = NULL;
ogs_sock_t *sock = NULL;
/* PFCP Server */
ogs_list_for_each(&ogs_pfcp_self()->pfcp_list, node) {
sock = ogs_pfcp_server(node);
if (!sock) return OGS_ERROR;
node->poll = ogs_pollset_add(ogs_app()->pollset,
2020-04-26 19:36:05 +00:00
OGS_POLLIN, sock->fd, pfcp_recv_cb, sock);
ogs_assert(node->poll);
2020-04-26 19:36:05 +00:00
}
ogs_list_for_each(&ogs_pfcp_self()->pfcp_list6, node) {
sock = ogs_pfcp_server(node);
if (!sock) return OGS_ERROR;
2020-04-26 19:36:05 +00:00
node->poll = ogs_pollset_add(ogs_app()->pollset,
2020-04-26 19:36:05 +00:00
OGS_POLLIN, sock->fd, pfcp_recv_cb, sock);
ogs_assert(node->poll);
2020-04-26 19:36:05 +00:00
}
2021-03-15 01:01:55 +00:00
OGS_SETUP_PFCP_SERVER;
2020-05-14 17:38:26 +00:00
2020-04-26 19:36:05 +00:00
return OGS_OK;
}
void upf_pfcp_close(void)
{
2020-05-14 17:38:26 +00:00
ogs_pfcp_node_t *pfcp_node = NULL;
2021-03-15 01:01:55 +00:00
ogs_list_for_each(&ogs_pfcp_self()->pfcp_peer_list, pfcp_node)
2020-05-14 17:38:26 +00:00
pfcp_node_fsm_fini(pfcp_node);
2023-02-23 07:59:59 +00:00
ogs_freeaddrinfo(ogs_pfcp_self()->pfcp_advertise);
ogs_freeaddrinfo(ogs_pfcp_self()->pfcp_advertise6);
2020-04-26 19:36:05 +00:00
ogs_socknode_remove_all(&ogs_pfcp_self()->pfcp_list);
ogs_socknode_remove_all(&ogs_pfcp_self()->pfcp_list6);
}
int upf_pfcp_send_session_establishment_response(
2020-04-26 19:36:05 +00:00
ogs_pfcp_xact_t *xact, upf_sess_t *sess,
ogs_pfcp_pdr_t *created_pdr[], int num_of_created_pdr)
{
int rv;
ogs_pkbuf_t *n4buf = NULL;
ogs_pfcp_header_t h;
ogs_assert(xact);
memset(&h, 0, sizeof(ogs_pfcp_header_t));
h.type = OGS_PFCP_SESSION_ESTABLISHMENT_RESPONSE_TYPE;
h.seid = sess->smf_n4_f_seid.seid;
2020-04-26 19:36:05 +00:00
n4buf = upf_n4_build_session_establishment_response(
h.type, sess, created_pdr, num_of_created_pdr);
if (!n4buf) {
ogs_error("upf_n4_build_session_establishment_response() failed");
return OGS_ERROR;
}
2020-04-26 19:36:05 +00:00
rv = ogs_pfcp_xact_update_tx(xact, &h, n4buf);
if (rv != OGS_OK) {
ogs_error("ogs_pfcp_xact_update_tx() failed");
return OGS_ERROR;
}
2020-04-26 19:36:05 +00:00
rv = ogs_pfcp_xact_commit(xact);
ogs_expect(rv == OGS_OK);
return rv;
2020-04-26 19:36:05 +00:00
}
int upf_pfcp_send_session_modification_response(
2020-04-26 19:36:05 +00:00
ogs_pfcp_xact_t *xact, upf_sess_t *sess,
ogs_pfcp_pdr_t *created_pdr[], int num_of_created_pdr)
{
int rv;
ogs_pkbuf_t *n4buf = NULL;
ogs_pfcp_header_t h;
ogs_assert(xact);
memset(&h, 0, sizeof(ogs_pfcp_header_t));
h.type = OGS_PFCP_SESSION_MODIFICATION_RESPONSE_TYPE;
h.seid = sess->smf_n4_f_seid.seid;
2020-04-26 19:36:05 +00:00
n4buf = upf_n4_build_session_modification_response(
h.type, sess, created_pdr, num_of_created_pdr);
if (!n4buf) {
ogs_error("upf_n4_build_session_modification_response() failed");
return OGS_ERROR;
}
2020-04-26 19:36:05 +00:00
rv = ogs_pfcp_xact_update_tx(xact, &h, n4buf);
if (rv != OGS_OK) {
ogs_error("ogs_pfcp_xact_update_tx() failed");
return OGS_ERROR;
}
2020-04-26 19:36:05 +00:00
rv = ogs_pfcp_xact_commit(xact);
ogs_expect(rv == OGS_OK);
return rv;
2020-04-26 19:36:05 +00:00
}
int upf_pfcp_send_session_deletion_response(ogs_pfcp_xact_t *xact,
2020-04-26 19:36:05 +00:00
upf_sess_t *sess)
{
int rv;
ogs_pkbuf_t *n4buf = NULL;
ogs_pfcp_header_t h;
ogs_assert(xact);
memset(&h, 0, sizeof(ogs_pfcp_header_t));
h.type = OGS_PFCP_SESSION_DELETION_RESPONSE_TYPE;
h.seid = sess->smf_n4_f_seid.seid;
2020-04-26 19:36:05 +00:00
n4buf = upf_n4_build_session_deletion_response(h.type, sess);
if (!n4buf) {
ogs_error("upf_n4_build_session_deletion_response() failed");
return OGS_ERROR;
}
2020-04-26 19:36:05 +00:00
rv = ogs_pfcp_xact_update_tx(xact, &h, n4buf);
if (rv != OGS_OK) {
ogs_error("ogs_pfcp_xact_update_tx() failed");
return OGS_ERROR;
}
2020-04-26 19:36:05 +00:00
rv = ogs_pfcp_xact_commit(xact);
ogs_expect(rv == OGS_OK);
return rv;
2020-04-26 19:36:05 +00:00
}
2021-01-18 16:48:35 +00:00
static void sess_timeout(ogs_pfcp_xact_t *xact, void *data)
{
uint8_t type;
ogs_assert(xact);
type = xact->seq[0].type;
switch (type) {
case OGS_PFCP_SESSION_REPORT_REQUEST_TYPE:
ogs_error("No PFCP session report response");
break;
default:
ogs_error("Not implemented [type:%d]", type);
break;
}
}
int upf_pfcp_send_session_report_request(
2021-01-18 16:48:35 +00:00
upf_sess_t *sess, ogs_pfcp_user_plane_report_t *report)
{
int rv;
ogs_pkbuf_t *n4buf = NULL;
ogs_pfcp_header_t h;
ogs_pfcp_xact_t *xact = NULL;
[UPF] Add metrics support Expose metrics with labels according to ETSI TS 128 552 V16.13.0 in UPF by using hash. The metrics are named respecting the rule: <generation>_<measurement_object_class>_<measurement_family_name>_<metric_name_as_in_TS_128_552> 5qi is not available in UPF. To present 5qi to the user, MN will have to maintain a table qfi->5qi for each QoS flow (will have to get information from SMF). So UPF has to expose qfi. qfi itself is not useful. When used, UPF will have to expose additional label to define the session (e.g. source interface). Label dnn is set to value of APN/DNN received in Establishment. Since SMF does not add APN/DNN to Establishment, the label is empty. When APN/DNN will be set by SMF, it should be added to sess in UPF and used in metrics on Modification and Deletion. Both datavolumeqosleveln3upf are exposed in bytes. MN is providing the transformation to kbits. fivegs_upffunction_upf_qosflows should expose the number of QFIs used in sessions, but exposes number of QER rules, which is currently equal to QFIs. The label snsssai is not provided since the slice is not available on UPF. Exposed metrics example: Standard counters: fivegs_ep_n3_gtp_indatapktn3upf 28637 fivegs_ep_n3_gtp_outdatapktn3upf 14729 fivegs_upffunction_sm_n4sessionestabreq 4 fivegs_upffunction_sm_n4sessionestabfail{cause="66"} 1 fivegs_upffunction_sm_n4sessionestabfail{cause="71"} 68 fivegs_upffunction_sm_n4sessionestabfail{cause="68"} 4 fivegs_upffunction_sm_n4sessionestabfail{cause="72"} 15 fivegs_upffunction_sm_n4sessionestabfail{cause="75"} 3 fivegs_upffunction_sm_n4sessionestabfail{cause="65"} 4 fivegs_upffunction_sm_n4sessionreport 0 fivegs_upffunction_sm_n4sessionreportsucc 0 fivegs_ep_n3_gtp_indatavolumeqosleveln3upf{qfi="1"} 39792997 fivegs_ep_n3_gtp_outdatavolumeqosleveln3upf{qfi="1"} 737548 Nonstandard gauge (added for controlling purposes - same metric as existing metric on AMF and SMF): fivegs_upffunction_upf_sessionnbr 1 Standard gauge: fivegs_upffunction_upf_qosflows{dnn=""} 1
2022-08-19 12:08:27 +00:00
upf_metrics_inst_global_inc(UPF_METR_GLOB_CTR_SM_N4SESSIONREPORT);
2021-01-18 16:48:35 +00:00
ogs_assert(sess);
ogs_assert(report);
memset(&h, 0, sizeof(ogs_pfcp_header_t));
h.type = OGS_PFCP_SESSION_REPORT_REQUEST_TYPE;
h.seid = sess->smf_n4_f_seid.seid;
2021-01-18 16:48:35 +00:00
xact = ogs_pfcp_xact_local_create(sess->pfcp_node, sess_timeout, sess);
if (!xact) {
ogs_error("ogs_pfcp_xact_local_create() failed");
return OGS_ERROR;
}
2021-01-18 16:48:35 +00:00
n4buf = ogs_pfcp_build_session_report_request(h.type, report);
if (!n4buf) {
ogs_error("ogs_pfcp_build_session_report_request() failed");
return OGS_ERROR;
}
2021-01-18 16:48:35 +00:00
rv = ogs_pfcp_xact_update_tx(xact, &h, n4buf);
if (rv != OGS_OK) {
ogs_error("ogs_pfcp_xact_update_tx() failed");
return OGS_ERROR;
}
2021-01-18 16:48:35 +00:00
rv = ogs_pfcp_xact_commit(xact);
ogs_expect(rv == OGS_OK);
return rv;
}