open5gs/src/pcf/init.c

160 lines
4.2 KiB
C
Raw Permalink Normal View History

2020-12-11 19:03:20 +00:00
/*
* Copyright (C) 2019-2023 by Sukchan Lee <acetcom@gmail.com>
2020-12-11 19:03:20 +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 "sbi-path.h"
[PCF] Add metrics support Expose metrics with labels according to ETSI TS 128 552 V16.13.0 in PCF by using hash. The metrics are named respecting the rule: <generation>_<measurement_object_class>_<measurement_family_name>_<metric_name_as_in_TS_128_552> Since slice itself is not unique, the plmnid label is exposed in addition to snssai. AM policy: fivegs_pcffunction_pa_policyamassoreq and fivegs_pcffunction_pa_policyamassosucc do not expose snssai label since it is not available at the time of exposure. plmnid is defined during AM policy processing, so not to lose the difference to ...succ, the basic metric fivegs_pcffunction_pa_policyamassoreq is preserved. SM policy: snssai is defined during SM policy processing, so not to lose the difference to ...succ, the basic metric fivegs_pcffunction_pa_policysmassoreq is preserved. Those 2 basic metrics retain their position but are exposed with empty labels. Metrics with labels are called later, when the label values are known. Exposed metrics example: -standard counters: fivegs_pcffunction_pa_policyamassoreq{plmnid=""} 3 fivegs_pcffunction_pa_policyamassoreq{plmnid="99970"} 3 fivegs_pcffunction_pa_policyamassosucc{plmnid="99970"} 3 fivegs_pcffunction_pa_policysmassoreq{plmnid="",snssai=""} 3 fivegs_pcffunction_pa_policysmassoreq{plmnid="99970",snssai="1000009"} 3 fivegs_pcffunction_pa_policysmassosucc{plmnid="99970",snssai="1000009"} 3 -nonstandard gauge (added for controlling purposes - same metric as existing metric on AMF and SMF): fivegs_pcffunction_pa_sessionnbr{plmnid="99970",snssai="1000009"} 0
2022-08-18 10:20:26 +00:00
#include "metrics.h"
2020-12-11 19:03:20 +00:00
static ogs_thread_t *thread;
static void pcf_main(void *data);
static int initialized = 0;
2023-04-04 12:53:39 +00:00
int pcf_initialize(void)
2020-12-11 19:03:20 +00:00
{
int rv;
#define APP_NAME "pcf"
rv = ogs_app_parse_local_conf(APP_NAME);
if (rv != OGS_OK) return rv;
pcf_metrics_init();
ogs_sbi_context_init(OpenAPI_nf_type_PCF);
2020-12-11 19:03:20 +00:00
pcf_context_init();
rv = ogs_log_config_domain(
ogs_app()->logger.domain, ogs_app()->logger.level);
if (rv != OGS_OK) return rv;
rv = ogs_sbi_context_parse_config(APP_NAME, "nrf", "scp");
2020-12-11 19:03:20 +00:00
if (rv != OGS_OK) return rv;
rv = ogs_metrics_context_parse_config(APP_NAME);
[PCF] Add metrics support Expose metrics with labels according to ETSI TS 128 552 V16.13.0 in PCF by using hash. The metrics are named respecting the rule: <generation>_<measurement_object_class>_<measurement_family_name>_<metric_name_as_in_TS_128_552> Since slice itself is not unique, the plmnid label is exposed in addition to snssai. AM policy: fivegs_pcffunction_pa_policyamassoreq and fivegs_pcffunction_pa_policyamassosucc do not expose snssai label since it is not available at the time of exposure. plmnid is defined during AM policy processing, so not to lose the difference to ...succ, the basic metric fivegs_pcffunction_pa_policyamassoreq is preserved. SM policy: snssai is defined during SM policy processing, so not to lose the difference to ...succ, the basic metric fivegs_pcffunction_pa_policysmassoreq is preserved. Those 2 basic metrics retain their position but are exposed with empty labels. Metrics with labels are called later, when the label values are known. Exposed metrics example: -standard counters: fivegs_pcffunction_pa_policyamassoreq{plmnid=""} 3 fivegs_pcffunction_pa_policyamassoreq{plmnid="99970"} 3 fivegs_pcffunction_pa_policyamassosucc{plmnid="99970"} 3 fivegs_pcffunction_pa_policysmassoreq{plmnid="",snssai=""} 3 fivegs_pcffunction_pa_policysmassoreq{plmnid="99970",snssai="1000009"} 3 fivegs_pcffunction_pa_policysmassosucc{plmnid="99970",snssai="1000009"} 3 -nonstandard gauge (added for controlling purposes - same metric as existing metric on AMF and SMF): fivegs_pcffunction_pa_sessionnbr{plmnid="99970",snssai="1000009"} 0
2022-08-18 10:20:26 +00:00
if (rv != OGS_OK) return rv;
2020-12-11 19:03:20 +00:00
rv = pcf_context_parse_config();
if (rv != OGS_OK) return rv;
ogs_metrics_context_open(ogs_metrics_self());
2022-12-06 13:57:36 +00:00
if (ogs_app()->db_uri) {
rv = ogs_dbi_init(ogs_app()->db_uri);
if (rv != OGS_OK) return rv;
}
2021-01-01 02:07:08 +00:00
rv = pcf_sbi_open();
if (rv != OGS_OK) return rv;
2020-12-11 19:03:20 +00:00
thread = ogs_thread_create(pcf_main, NULL);
if (!thread) return OGS_ERROR;
initialized = 1;
return OGS_OK;
}
static ogs_timer_t *t_termination_holding = NULL;
static void event_termination(void)
{
ogs_sbi_nf_instance_t *nf_instance = NULL;
/* Sending NF Instance De-registeration to NRF */
ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance)
ogs_sbi_nf_fsm_fini(nf_instance);
2020-12-11 19:03:20 +00:00
/* Starting holding timer */
t_termination_holding = ogs_timer_add(ogs_app()->timer_mgr, NULL, NULL);
ogs_assert(t_termination_holding);
#define TERMINATION_HOLDING_TIME ogs_time_from_msec(300)
ogs_timer_start(t_termination_holding, TERMINATION_HOLDING_TIME);
/* Sending termination event to the queue */
ogs_queue_term(ogs_app()->queue);
ogs_pollset_notify(ogs_app()->pollset);
}
void pcf_terminate(void)
{
if (!initialized) return;
/* Daemon terminating */
event_termination();
ogs_thread_destroy(thread);
ogs_timer_delete(t_termination_holding);
pcf_sbi_close();
ogs_metrics_context_close(ogs_metrics_self());
if (ogs_app()->db_uri) {
ogs_dbi_final();
}
2021-01-01 02:07:08 +00:00
2020-12-11 19:03:20 +00:00
pcf_context_final();
ogs_sbi_context_final();
pcf_metrics_final();
2020-12-11 19:03:20 +00:00
}
static void pcf_main(void *data)
{
ogs_fsm_t pcf_sm;
int rv;
ogs_fsm_init(&pcf_sm, pcf_state_initial, pcf_state_final, 0);
2020-12-11 19:03:20 +00:00
for ( ;; ) {
ogs_pollset_poll(ogs_app()->pollset,
ogs_timer_mgr_next(ogs_app()->timer_mgr));
/*
* After ogs_pollset_poll(), ogs_timer_mgr_expire() must be called.
*
* The reason is why ogs_timer_mgr_next() can get the corrent value
* when ogs_timer_stop() is called internally in ogs_timer_mgr_expire().
*
* You should not use event-queue before ogs_timer_mgr_expire().
* In this case, ogs_timer_mgr_expire() does not work
* because 'if rv == OGS_DONE' statement is exiting and
* not calling ogs_timer_mgr_expire().
*/
ogs_timer_mgr_expire(ogs_app()->timer_mgr);
for ( ;; ) {
pcf_event_t *e = NULL;
rv = ogs_queue_trypop(ogs_app()->queue, (void**)&e);
ogs_assert(rv != OGS_ERROR);
if (rv == OGS_DONE)
goto done;
if (rv == OGS_RETRY)
break;
ogs_assert(e);
ogs_fsm_dispatch(&pcf_sm, e);
ogs_event_free(e);
2020-12-11 19:03:20 +00:00
}
}
done:
ogs_fsm_fini(&pcf_sm, 0);
}