Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pespin committed Apr 7, 2024
1 parent bbdfca2 commit ed45586
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions src/upf/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ uint8_t upf_sess_set_ue_ipv6_framed_routes(upf_sess_t *sess,
void upf_sess_urr_acc_add(upf_sess_t *sess, ogs_pfcp_urr_t *urr, size_t size, bool is_uplink)
{
upf_sess_urr_acc_t *urr_acc = &sess->urr_acc[urr->id];
uint64_t threshold;
uint64_t vol;

/* Increment total & ul octets + pkts */
Expand All @@ -692,8 +693,10 @@ void upf_sess_urr_acc_add(upf_sess_t *sess, ogs_pfcp_urr_t *urr, size_t size, bo

/* generate report if volume threshold/quota is reached */
vol = urr_acc->total_octets - urr_acc->last_report.total_octets;
if ((urr->rep_triggers.volume_quota && urr->vol_quota.tovol && vol >= urr->vol_quota.total_volume) ||
(urr->rep_triggers.volume_threshold && urr->vol_threshold.tovol && vol >= urr->vol_threshold.total_volume)) {
threshold = (urr->rep_triggers.volume_threshold && urr->vol_threshold.tovol) ?
urr->vol_threshold.total_volume : 0;
if (urr->rep_triggers.volume_quota && urr->vol_quota.tovol &&
(vol + threshold) >= urr->vol_quota.total_volume) {
ogs_pfcp_user_plane_report_t report;
memset(&report, 0, sizeof(report));
upf_sess_urr_acc_fill_usage_report(sess, urr, &report, 0);
Expand All @@ -713,6 +716,7 @@ void upf_sess_urr_acc_fill_usage_report(upf_sess_t *sess, const ogs_pfcp_urr_t *
ogs_pfcp_user_plane_report_t *report, unsigned int idx)
{
upf_sess_urr_acc_t *urr_acc = &sess->urr_acc[urr->id];
uint64_t threshold;
ogs_time_t last_report_timestamp;
ogs_time_t now;

Expand Down Expand Up @@ -752,20 +756,24 @@ void upf_sess_urr_acc_fill_usage_report(upf_sess_t *sess, const ogs_pfcp_urr_t *
if (urr->quota_validity_time > 0 &&
report->usage_report[idx].dur_measurement >= urr->quota_validity_time)
report->usage_report[idx].rep_trigger.quota_validity_time = 1;
if (urr->time_quota > 0 &&
report->usage_report[idx].dur_measurement >= urr->time_quota)
report->usage_report[idx].rep_trigger.time_quota = 1;
if (urr->time_threshold > 0 &&
report->usage_report[idx].dur_measurement >= urr->time_threshold)
report->usage_report[idx].rep_trigger.time_threshold = 1;
if (urr->time_quota > 0) {
if (report->usage_report[idx].dur_measurement >= urr->time_quota)
report->usage_report[idx].rep_trigger.time_quota = 1;
if (urr->time_threshold > 0 &&
(report->usage_report[idx].dur_measurement + urr->time_threshold) >= urr->time_quota)
report->usage_report[idx].rep_trigger.time_threshold = 1;
}

/* Volume triggers: */
if (urr->rep_triggers.volume_quota && urr->vol_quota.tovol &&
report->usage_report[idx].vol_measurement.total_volume >= urr->vol_quota.total_volume)
report->usage_report[idx].rep_trigger.volume_quota = 1;
if (urr->rep_triggers.volume_threshold && urr->vol_threshold.tovol &&
report->usage_report[idx].vol_measurement.total_volume >= urr->vol_threshold.total_volume)
report->usage_report[idx].rep_trigger.volume_threshold = 1;
if (urr->rep_triggers.volume_quota && urr->vol_quota.tovol) {
if (report->usage_report[idx].vol_measurement.total_volume >= urr->vol_quota.total_volume)
report->usage_report[idx].rep_trigger.volume_quota = 1;
threshold = (urr->rep_triggers.volume_threshold && urr->vol_threshold.tovol) ?
urr->vol_threshold.total_volume : 0;
if (threshold &&
(report->usage_report[idx].vol_measurement.total_volume + threshold) >= urr->vol_quota.total_volume)
report->usage_report[idx].rep_trigger.volume_threshold = 1;
}
}

void upf_sess_urr_acc_snapshot(upf_sess_t *sess, ogs_pfcp_urr_t *urr)
Expand Down Expand Up @@ -838,20 +846,28 @@ static void upf_sess_urr_acc_time_threshold_setup(upf_sess_t *sess, ogs_pfcp_urr
if (!urr_acc->t_time_threshold)
urr_acc->t_time_threshold = ogs_timer_add(ogs_app()->timer_mgr,
upf_sess_urr_acc_timers_cb, urr);

/* Taken care by caller: */
ogs_assert(urr->time_quota >= urr->time_threshold);

ogs_timer_start(urr_acc->t_time_threshold,
ogs_time_from_sec(urr->time_threshold));
ogs_time_from_sec(urr->time_quota - urr->time_threshold));
}

void upf_sess_urr_acc_timers_setup(upf_sess_t *sess, ogs_pfcp_urr_t *urr)
{
upf_sess_urr_acc_t *urr_acc = &sess->urr_acc[urr->id];

urr_acc->time_start = ogs_time_ntp32_now();
if (urr->rep_triggers.quota_validity_time && urr->quota_validity_time > 0)
upf_sess_urr_acc_validity_time_setup(sess, urr);
if (urr->rep_triggers.time_quota && urr->time_quota > 0)
upf_sess_urr_acc_time_quota_setup(sess, urr);
if (urr->rep_triggers.time_threshold && urr->time_threshold > 0)
upf_sess_urr_acc_time_threshold_setup(sess, urr);
if (urr->rep_triggers.time_quota && urr->time_quota > 0) {
if (urr->rep_triggers.time_threshold && urr->time_threshold > 0 &&
urr->time_threshold < urr->time_quota)
upf_sess_urr_acc_time_threshold_setup(sess, urr);
else
upf_sess_urr_acc_time_quota_setup(sess, urr);
}
}

static void upf_sess_urr_acc_remove_all(upf_sess_t *sess)
Expand Down

0 comments on commit ed45586

Please sign in to comment.