open5gs/src/upf/context.h

163 lines
5.1 KiB
C
Raw Permalink Normal View History

2020-04-26 19:36:05 +00:00
/*
* Copyright (C) 2019-2023 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/>.
*/
#ifndef UPF_CONTEXT_H
#define UPF_CONTEXT_H
#include "upf-config.h"
#if HAVE_NET_IF_H
#include <net/if.h>
#endif
#include "ogs-gtp.h"
#include "ogs-pfcp.h"
#include "ogs-app.h"
#include "ipfw/ogs-ipfw.h"
2020-05-14 17:38:26 +00:00
#include "timer.h"
#include "upf-sm.h"
[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
#include "metrics.h"
2020-05-14 17:38:26 +00:00
2020-04-26 19:36:05 +00:00
#ifdef __cplusplus
extern "C" {
#endif
extern int __upf_log_domain;
#undef OGS_LOG_DOMAIN
#define OGS_LOG_DOMAIN __upf_log_domain
2023-01-18 11:32:42 +00:00
struct upf_route_trie_node;
2020-04-26 19:36:05 +00:00
2023-01-18 11:32:42 +00:00
typedef struct upf_context_s {
ogs_hash_t *upf_n4_seid_hash; /* hash table (UPF-N4-SEID) */
ogs_hash_t *smf_n4_seid_hash; /* hash table (SMF-N4-SEID) */
ogs_hash_t *smf_n4_f_seid_hash; /* hash table (SMF-N4-F-SEID) */
ogs_hash_t *ipv4_hash; /* hash table (IPv4 Address) */
ogs_hash_t *ipv6_hash; /* hash table (IPv6 Address) */
/* IPv4 framed routes trie */
struct upf_route_trie_node *ipv4_framed_routes;
/* IPv6 framed routes trie */
struct upf_route_trie_node *ipv6_framed_routes;
ogs_list_t sess_list;
2020-04-26 19:36:05 +00:00
} upf_context_t;
2023-01-18 11:32:42 +00:00
/* trie mapping from IP framed routes to session. */
struct upf_route_trie_node {
struct upf_route_trie_node *left;
struct upf_route_trie_node *right;
upf_sess_t *sess;
};
/* Accounting: */
typedef struct upf_sess_urr_acc_s {
bool reporting_enabled;
ogs_timer_t *t_validity_time; /* Quota Validity Time expiration handler */
ogs_timer_t *t_time_quota; /* Time Quota expiration handler */
ogs_timer_t *t_time_threshold; /* Time Threshold expiration handler */
uint32_t time_start; /* When t_time_* started */
ogs_pfcp_urr_ur_seqn_t report_seqn; /* Next seqn to use when reporting */
uint64_t total_octets;
uint64_t ul_octets;
uint64_t dl_octets;
uint64_t total_pkts;
uint64_t ul_pkts;
uint64_t dl_pkts;
ogs_time_t time_of_first_packet;
ogs_time_t time_of_last_packet;
/* Snapshot of measurement when last report was sent: */
struct {
uint64_t total_octets;
uint64_t ul_octets;
uint64_t dl_octets;
uint64_t total_pkts;
uint64_t ul_pkts;
uint64_t dl_pkts;
ogs_time_t timestamp;
} last_report;
} upf_sess_urr_acc_t;
2020-04-26 19:36:05 +00:00
#define UPF_SESS(pfcp_sess) ogs_container_of(pfcp_sess, upf_sess_t, pfcp)
typedef struct upf_sess_s {
ogs_lnode_t lnode;
ogs_pool_id_t *upf_n4_seid_node; /* A node of UPF-N4-SEID */
2020-04-26 19:36:05 +00:00
ogs_pfcp_sess_t pfcp;
uint64_t upf_n4_seid; /* UPF SEID is dervied from NODE */
struct {
uint64_t seid;
ogs_ip_t ip;
} smf_n4_f_seid; /* SMF SEID is received from Peer */
2020-04-26 19:36:05 +00:00
/* APN Configuration */
ogs_pfcp_ue_ip_t *ipv4;
ogs_pfcp_ue_ip_t *ipv6;
2023-01-18 11:32:42 +00:00
ogs_ipsubnet_t *ipv4_framed_routes;
ogs_ipsubnet_t *ipv6_framed_routes;
2020-04-26 19:36:05 +00:00
char *gx_sid; /* Gx Session ID */
ogs_pfcp_node_t *pfcp_node;
/* Accounting: */
upf_sess_urr_acc_t urr_acc[OGS_MAX_NUM_OF_URR]; /* FIXME: This probably needs to be mved to a hashtable or alike */
char *apn_dnn; /* APN/DNN Item */
2020-04-26 19:36:05 +00:00
} upf_sess_t;
void upf_context_init(void);
void upf_context_final(void);
upf_context_t *upf_self(void);
int upf_context_parse_config(void);
upf_sess_t *upf_sess_add_by_message(ogs_pfcp_message_t *message);
upf_sess_t *upf_sess_add(ogs_pfcp_f_seid_t *f_seid);
2020-04-26 19:36:05 +00:00
int upf_sess_remove(upf_sess_t *sess);
void upf_sess_remove_all(void);
upf_sess_t *upf_sess_find_by_smf_n4_seid(uint64_t seid);
upf_sess_t *upf_sess_find_by_smf_n4_f_seid(ogs_pfcp_f_seid_t *f_seid);
upf_sess_t *upf_sess_find_by_upf_n4_seid(uint64_t seid);
2020-04-26 19:36:05 +00:00
upf_sess_t *upf_sess_find_by_ipv4(uint32_t addr);
upf_sess_t *upf_sess_find_by_ipv6(uint32_t *addr6);
uint8_t upf_sess_set_ue_ip(upf_sess_t *sess,
uint8_t session_type, ogs_pfcp_pdr_t *pdr);
2023-01-18 11:32:42 +00:00
uint8_t upf_sess_set_ue_ipv4_framed_routes(upf_sess_t *sess,
char *framed_routes[]);
uint8_t upf_sess_set_ue_ipv6_framed_routes(upf_sess_t *sess,
char *framed_routes[]);
void upf_sess_urr_acc_add(upf_sess_t *sess, ogs_pfcp_urr_t *urr, size_t size, bool is_uplink);
void upf_sess_urr_acc_fill_usage_report(upf_sess_t *sess, const ogs_pfcp_urr_t *urr,
ogs_pfcp_user_plane_report_t *report, unsigned int idx);
void upf_sess_urr_acc_snapshot(upf_sess_t *sess, ogs_pfcp_urr_t *urr);
void upf_sess_urr_acc_timers_setup(upf_sess_t *sess, ogs_pfcp_urr_t *urr);
2020-04-26 19:36:05 +00:00
#ifdef __cplusplus
}
#endif
#endif /* UPF_CONTEXT_H */