open5gs/src/pcf/nudr-handler.c

260 lines
8.8 KiB
C
Raw Normal View History

2020-12-11 19:03:20 +00:00
/*
* Copyright (C) 2019,2020 by Sukchan Lee <acetcom@gmail.com>
*
* 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"
2020-12-11 19:03:20 +00:00
#include "nudr-handler.h"
bool pcf_nudr_dr_handle_query_am_data(
pcf_ue_t *pcf_ue, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg)
{
2021-01-01 02:07:08 +00:00
int rv, status = 0;
2020-12-11 19:03:20 +00:00
char *strerror = NULL;
ogs_sbi_server_t *server = NULL;
ogs_sbi_message_t sendmsg;
ogs_sbi_header_t header;
ogs_sbi_response_t *response = NULL;
ogs_subscription_data_t subscription_data;
2020-12-11 19:03:20 +00:00
ogs_assert(pcf_ue);
ogs_assert(stream);
server = ogs_sbi_server_from_stream(stream);
ogs_assert(server);
ogs_assert(recvmsg);
memset(&subscription_data, 0, sizeof(ogs_subscription_data_t));
2020-12-11 19:03:20 +00:00
SWITCH(recvmsg->h.resource.component[3])
CASE(OGS_SBI_RESOURCE_NAME_AM_DATA)
OpenAPI_policy_association_t PolicyAssociation;
2021-01-01 02:07:08 +00:00
OpenAPI_ambr_t UeAmbr;
OpenAPI_list_t *TriggerList = NULL;
OpenAPI_lnode_t *node = NULL;
2020-12-11 19:03:20 +00:00
if (!recvmsg->AmPolicyData) {
strerror = ogs_msprintf("[%s] No AmPolicyData", pcf_ue->supi);
2021-01-01 02:07:08 +00:00
status = OGS_SBI_HTTP_STATUS_BAD_REQUEST;
2020-12-11 19:03:20 +00:00
goto cleanup;
}
if (!pcf_ue->policy_association_request) {
strerror = ogs_msprintf("[%s] No PolicyAssociationRequest",
pcf_ue->supi);
2021-01-01 02:07:08 +00:00
status = OGS_SBI_HTTP_STATUS_BAD_REQUEST;
goto cleanup;
}
rv = ogs_dbi_subscription_data(pcf_ue->supi, &subscription_data);
if (rv != OGS_OK) {
strerror = ogs_msprintf("[%s] Cannot find SUPI in DB",
pcf_ue->supi);
status = OGS_SBI_HTTP_STATUS_NOT_FOUND;
goto cleanup;
}
if (!subscription_data.ambr.uplink &&
!subscription_data.ambr.downlink) {
ogs_error("[%s] No UE-AMBR", pcf_ue->supi);
status = OGS_SBI_HTTP_STATUS_NOT_FOUND;
2020-12-11 19:03:20 +00:00
goto cleanup;
}
memset(&PolicyAssociation, 0, sizeof(PolicyAssociation));
PolicyAssociation.request = pcf_ue->policy_association_request;
2021-01-01 02:07:08 +00:00
PolicyAssociation.supp_feat =
ogs_uint64_to_string(pcf_ue->am_policy_control_features);
ogs_assert(PolicyAssociation.supp_feat);
TriggerList = OpenAPI_list_create();
ogs_assert(TriggerList);
memset(&UeAmbr, 0, sizeof(UeAmbr));
if (OGS_SBI_FEATURES_IS_SET(pcf_ue->am_policy_control_features,
OGS_SBI_NPCF_AM_POLICY_CONTROL_UE_AMBR_AUTHORIZATION)) {
if (pcf_ue->subscribed_ue_ambr) {
ogs_bitrate_t subscribed_ue_ambr;
subscribed_ue_ambr.uplink = ogs_sbi_bitrate_from_string(
pcf_ue->subscribed_ue_ambr->uplink);
subscribed_ue_ambr.downlink = ogs_sbi_bitrate_from_string(
pcf_ue->subscribed_ue_ambr->downlink);
if (((subscribed_ue_ambr.uplink / 1024) !=
(subscription_data.ambr.uplink / 1024)) ||
((subscribed_ue_ambr.downlink / 1024) !=
(subscription_data.ambr.downlink / 1024))) {
OpenAPI_list_add(TriggerList,
(void *)OpenAPI_request_trigger_UE_AMBR_CH);
}
UeAmbr.uplink = ogs_sbi_bitrate_to_string(
subscription_data.ambr.uplink, OGS_SBI_BITRATE_KBPS);
UeAmbr.downlink = ogs_sbi_bitrate_to_string(
subscription_data.ambr.downlink, OGS_SBI_BITRATE_KBPS);
PolicyAssociation.ue_ambr = &UeAmbr;
}
}
if (TriggerList->count)
PolicyAssociation.triggers = TriggerList;
2020-12-11 19:03:20 +00:00
memset(&header, 0, sizeof(header));
header.service.name =
(char *)OGS_SBI_SERVICE_NAME_NPCF_AM_POLICY_CONTROL;
header.api.version = (char *)OGS_SBI_API_V1;
header.resource.component[0] =
(char *)OGS_SBI_RESOURCE_NAME_POLICIES;
header.resource.component[1] = pcf_ue->association_id;
memset(&sendmsg, 0, sizeof(sendmsg));
sendmsg.PolicyAssociation = &PolicyAssociation;
sendmsg.http.location = ogs_sbi_server_uri(server, &header);
response = ogs_sbi_build_response(
&sendmsg, OGS_SBI_HTTP_STATUS_CREATED);
ogs_assert(response);
2021-06-06 13:35:46 +00:00
ogs_assert(true == ogs_sbi_server_send_response(stream, response));
2020-12-11 19:03:20 +00:00
ogs_free(sendmsg.http.location);
2021-01-01 02:07:08 +00:00
ogs_free(PolicyAssociation.supp_feat);
OpenAPI_list_free(TriggerList);
if (UeAmbr.uplink)
ogs_free(UeAmbr.uplink);
if (UeAmbr.downlink)
ogs_free(UeAmbr.downlink);
ogs_subscription_data_free(&subscription_data);
OpenAPI_list_for_each(PolicyAssociation.request->allowed_snssais, node) {
struct OpenAPI_snssai_s *Snssai = node->data;
if (Snssai) {
ogs_s_nssai_t s_nssai;
s_nssai.sst = Snssai->sst;
s_nssai.sd = ogs_s_nssai_sd_from_string(Snssai->sd);
pcf_metrics_inst_by_slice_add(&pcf_ue->guami.plmn_id,
&s_nssai, PCF_METR_CTR_PA_POLICYAMASSOSUCC, 1);
} else {
ogs_error("[%s] No Snssai", pcf_ue->supi);
}
}
[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
2020-12-11 19:03:20 +00:00
return true;
DEFAULT
strerror = ogs_msprintf("[%s] Invalid resource name [%s]",
pcf_ue->supi, recvmsg->h.resource.component[3]);
END
cleanup:
ogs_assert(strerror);
2021-01-01 02:07:08 +00:00
ogs_assert(status);
2020-12-11 19:03:20 +00:00
ogs_error("%s", strerror);
2021-06-06 13:35:46 +00:00
ogs_assert(true ==
ogs_sbi_server_send_error(stream, status, recvmsg, strerror, NULL));
2020-12-11 19:03:20 +00:00
ogs_free(strerror);
ogs_subscription_data_free(&subscription_data);
2020-12-11 19:03:20 +00:00
return false;
}
bool pcf_nudr_dr_handle_query_sm_data(
pcf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg)
{
int status = 0;
2020-12-11 19:03:20 +00:00
char *strerror = NULL;
pcf_ue_t *pcf_ue = NULL;
ogs_sbi_server_t *server = NULL;
int r;
2020-12-11 19:03:20 +00:00
ogs_assert(sess);
pcf_ue = sess->pcf_ue;
ogs_assert(pcf_ue);
ogs_assert(stream);
server = ogs_sbi_server_from_stream(stream);
ogs_assert(server);
ogs_assert(recvmsg);
SWITCH(recvmsg->h.resource.component[3])
CASE(OGS_SBI_RESOURCE_NAME_SM_DATA)
ogs_sbi_nf_instance_t *nf_instance = NULL;
ogs_sbi_service_type_e service_type = OGS_SBI_SERVICE_TYPE_NULL;
2020-12-11 19:03:20 +00:00
if (!recvmsg->SmPolicyData) {
strerror = ogs_msprintf("[%s:%d] No SmPolicyData",
pcf_ue->supi, sess->psi);
2021-01-01 02:07:08 +00:00
status = OGS_SBI_HTTP_STATUS_BAD_REQUEST;
goto cleanup;
}
service_type = OGS_SBI_SERVICE_TYPE_NPCF_POLICYAUTHORIZATION;
nf_instance = sess->sbi.service_type_array[service_type].nf_instance;
if (!nf_instance) {
OpenAPI_nf_type_e requester_nf_type =
NF_INSTANCE_TYPE(ogs_sbi_self()->nf_instance);
ogs_assert(requester_nf_type);
nf_instance = ogs_sbi_nf_instance_find_by_service_type(
service_type, requester_nf_type);
if (nf_instance)
OGS_SBI_SETUP_NF_INSTANCE(
sess->sbi.service_type_array[service_type],
nf_instance);
}
if (nf_instance) {
r = pcf_sess_sbi_discover_and_send(
OGS_SBI_SERVICE_TYPE_NBSF_MANAGEMENT, NULL,
pcf_nbsf_management_build_register,
sess, stream, nf_instance);
ogs_expect(r == OGS_OK);
ogs_assert(r != OGS_ERROR);
} else {
r = pcf_sess_sbi_discover_only(sess, stream, service_type);
ogs_expect(r == OGS_OK);
ogs_assert(r != OGS_ERROR);
}
2021-01-01 02:07:08 +00:00
2020-12-11 19:03:20 +00:00
return true;
DEFAULT
strerror = ogs_msprintf("[%s:%d] Invalid resource name [%s]",
pcf_ue->supi, sess->psi, recvmsg->h.resource.component[3]);
END
cleanup:
ogs_assert(strerror);
ogs_assert(status);
2020-12-11 19:03:20 +00:00
ogs_error("%s", strerror);
2021-06-06 13:35:46 +00:00
ogs_assert(true ==
ogs_sbi_server_send_error(stream, status, recvmsg, strerror, NULL));
2020-12-11 19:03:20 +00:00
ogs_free(strerror);
return false;
}