From 69831c43f512a2f5d5a1e0442d2b425742a5d1f8 Mon Sep 17 00:00:00 2001 From: Abdelmuhaimen Seaudi Date: Wed, 12 Apr 2023 22:31:01 +0200 Subject: [PATCH] add support for sigscale ocs added several changes to correctly work with sigscal ocs offline charging --- lib/diameter/common/message.h | 1 + src/smf/gy-handler.c | 6 ++++-- src/smf/gy-path.c | 30 ++++++++++++++++++++++++------ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/lib/diameter/common/message.h b/lib/diameter/common/message.h index 916f11a87..159394c43 100644 --- a/lib/diameter/common/message.h +++ b/lib/diameter/common/message.h @@ -40,6 +40,7 @@ extern "C" { #define OGS_DIAM_AUTHORIZATION_REJECTED 5003 #define OGS_DIAM_MISSING_AVP 5004 #define OGS_DIAM_INVALID_AVP_VALUE 5005 +#define OGS_DIAM_USER_UNKNOWN 5030 extern struct dict_object *ogs_diam_session_id; extern struct dict_object *ogs_diam_termination_cause; diff --git a/src/smf/gy-handler.c b/src/smf/gy-handler.c index ea2347e39..8ddadef45 100644 --- a/src/smf/gy-handler.c +++ b/src/smf/gy-handler.c @@ -197,10 +197,13 @@ void smf_gy_handle_cca_update_request( urr_update_time(sess, urr, gy_message); urr_update_volume(sess, urr, gy_message); + /* Associate accounting URR each direction PDR: */ ogs_pfcp_pdr_associate_urr(bearer->ul_pdr, urr); + ogs_pfcp_pdr_associate_urr(bearer->dl_pdr, urr); if (urr->meas_method != prev_meas_method) modify_flags |= OGS_PFCP_MODIFY_URR_MEAS_METHOD; + if (urr->rep_triggers.quota_validity_time != prev_rep_triggers.quota_validity_time || urr->rep_triggers.time_quota != prev_rep_triggers.time_quota || urr->rep_triggers.volume_quota != prev_rep_triggers.volume_quota || @@ -214,8 +217,7 @@ void smf_gy_handle_cca_update_request( if (urr->time_quota != prev_time_quota) modify_flags |= OGS_PFCP_MODIFY_URR_TIME_QUOTA; - if (urr->vol_quota.tovol != prev_vol_quota.tovol || - urr->vol_quota.total_volume != prev_vol_quota.total_volume) + if (urr->vol_quota.tovol || urr->vol_quota.total_volume) modify_flags |= OGS_PFCP_MODIFY_URR_VOLUME_QUOTA; if (urr->time_threshold != prev_time_threshold) diff --git a/src/smf/gy-path.c b/src/smf/gy-path.c index 325806928..681bc6a58 100644 --- a/src/smf/gy-path.c +++ b/src/smf/gy-path.c @@ -98,7 +98,16 @@ static void fill_multiple_services_credit_control_ccr(smf_sess_t *sess, /* CC-Time, RFC4006 8.21 */ /* CC-Money, RFC4006 8.22. Not used in 3GPP. */ + /* CC-Total-Octets, RFC4006 8.23 */ + ret = fd_msg_avp_new(ogs_diam_gy_cc_total_octets, 0, &avpch2); + ogs_assert(ret == 0); + val.u64 = 1000000; + ret = fd_msg_avp_setvalue (avpch2, &val); + ogs_assert(ret == 0); + ret = fd_msg_avp_add (avpch1, MSG_BRW_LAST_CHILD, avpch2); + ogs_assert(ret == 0); + /* CC-Input-Octets, RFC4006 8.24 */ /* CC-Output-Octets, RFC4006 8.25 */ /* CC-Service-Specific-Units, RFC4006 8.26 */ @@ -107,6 +116,8 @@ static void fill_multiple_services_credit_control_ccr(smf_sess_t *sess, ogs_assert(ret == 0); } + if (cc_request_type != OGS_DIAM_GY_CC_REQUEST_TYPE_INITIAL_REQUEST) { + /* Used-Service-Unit, RFC4006 8.18 */ ret = fd_msg_avp_new(ogs_diam_gy_used_service_unit, 0, &avpch1); ogs_assert(ret == 0); @@ -170,6 +181,7 @@ static void fill_multiple_services_credit_control_ccr(smf_sess_t *sess, ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); ogs_assert(ret == 0); + //bypass USU if we are in CCR INITIAL /* Service-Identifier, RFC4006 8.28. Not used in Gy. */ /* Rating-Group */ @@ -284,7 +296,7 @@ static void fill_multiple_services_credit_control_ccr(smf_sess_t *sess, ogs_assert(ret == 0); ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); ogs_assert(ret == 0); - + } /* Multiple Services AVP add to req: */ ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp); ogs_assert(ret == 0); @@ -294,6 +306,7 @@ static void fill_multiple_services_credit_control_ccr(smf_sess_t *sess, static void fill_service_information_ccr(smf_sess_t *sess, uint32_t cc_request_type, struct msg *req) { + int ret; union avp_value val; struct avp *avp; @@ -546,6 +559,7 @@ static void fill_service_information_ccr(smf_sess_t *sess, void smf_gy_send_ccr(smf_sess_t *sess, void *xact, uint32_t cc_request_type) { + int ret; smf_ue_t *smf_ue = NULL; @@ -556,7 +570,7 @@ void smf_gy_send_ccr(smf_sess_t *sess, void *xact, struct sess_state *sess_data = NULL, *svg; struct session *session = NULL; int new; - const char *service_context_id = "open5gs-smfd@open5gs.org"; + const char *service_context_id = "32251@3gpp.org"; uint32_t timestamp; ogs_assert(xact); @@ -587,7 +601,6 @@ void smf_gy_send_ccr(smf_sess_t *sess, void *xact, ogs_assert(new == 0); ogs_debug(" Found Gy Session-Id: [%s]", sess->gy_sid); - /* Add Session-Id to the message */ ret = ogs_diam_message_session_id_set(req, (os0_t)sess->gy_sid, sidlen); ogs_assert(ret == 0); @@ -618,12 +631,10 @@ void smf_gy_send_ccr(smf_sess_t *sess, void *xact, ogs_assert(sess_data); ogs_debug(" Allocate new Gy session: [%s]", sess_data->gy_sid); - /* Save Session-Id to SMF Session Context */ sess->gy_sid = (char *)sess_data->gy_sid; } else ogs_debug(" Retrieve Gy session: [%s]", sess_data->gy_sid); - /* * 8.2. CC-Request-Number AVP * @@ -647,16 +658,20 @@ void smf_gy_send_ccr(smf_sess_t *sess, void *xact, ogs_debug(" CC Request Type[%d] Number[%d]", sess_data->cc_request_type, sess_data->cc_request_number); - ogs_assert(sess_data->cc_request_number <= MAX_CC_REQUEST_NUMBER); + + ogs_assert(sess_data->cc_request_number < MAX_CC_REQUEST_NUMBER); + /* Update session state */ sess_data->sess = sess; + if (cc_request_type == OGS_DIAM_GY_CC_REQUEST_TYPE_UPDATE_REQUEST) sess_data->xact_data[sess_data->cc_request_number].pfcp = true; else sess_data->xact_data[sess_data->cc_request_number].pfcp = false; sess_data->xact_data[sess_data->cc_request_number].ptr = xact; + /* Origin-Host & Origin-Realm */ ret = fd_msg_add_origin(req, 0); ogs_assert(ret == 0); @@ -707,6 +722,8 @@ void smf_gy_send_ccr(smf_sess_t *sess, void *xact, ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp); ogs_assert(ret == 0); + + /* Set the Destination-Host AVP */ if (sess_data->peer_host) { ret = fd_msg_avp_new(ogs_diam_destination_host, 0, &avp); @@ -868,6 +885,7 @@ void smf_gy_send_ccr(smf_sess_t *sess, void *xact, ret = fd_msg_send(&req, smf_gy_cca_cb, svg); ogs_assert(ret == 0); + /* Increment the counter */ ogs_assert(pthread_mutex_lock(&ogs_diam_logger_self()->stats_lock) == 0); ogs_diam_logger_self()->stats.nb_sent++;