[sr-dev] git:master:6f46f87a: modules/ims_charging: add adjustments for rounding errors that creep in during interim charges

jaybeepee jason.penton at gmail.com
Thu Jan 14 10:22:21 CET 2016


Module: kamailio
Branch: master
Commit: 6f46f87acf7b3772a2bc8902e6e73e0bdc293851
URL: https://github.com/kamailio/kamailio/commit/6f46f87acf7b3772a2bc8902e6e73e0bdc293851

Author: jaybeepee <jason.penton at gmail.com>
Committer: jaybeepee <jason.penton at gmail.com>
Date: 2016-01-14T11:22:07+02:00

modules/ims_charging: add adjustments for rounding errors that creep in during interim charges
    - this is a result of Ro interface only supporting second-based resolution in diam. msgs. to OCS

---

Modified: modules/ims_charging/ims_ro.c
Modified: modules/ims_charging/ro_timer.c

---

Diff:  https://github.com/kamailio/kamailio/commit/6f46f87acf7b3772a2bc8902e6e73e0bdc293851.diff
Patch: https://github.com/kamailio/kamailio/commit/6f46f87acf7b3772a2bc8902e6e73e0bdc293851.patch

---

diff --git a/modules/ims_charging/ims_ro.c b/modules/ims_charging/ims_ro.c
index 8864788..3dafc2b 100644
--- a/modules/ims_charging/ims_ro.c
+++ b/modules/ims_charging/ims_ro.c
@@ -755,9 +755,29 @@ void send_ccr_stop(struct ro_session *ro_session) {
     long used = 0;
     str user_name = {0, 0};
     int ret = 0;
+    time_t stop_time;
+    time_t actual_time_micros;
+    int actual_time_seconds;
+
+    stop_time = get_current_time_micro();
+
+    if (ro_session->start_time == 0)
+        actual_time_micros = 0;
+    else
+        actual_time_micros = stop_time - ro_session->start_time;
+
+    actual_time_seconds = (actual_time_micros + (1000000 - 1)) / (float) 1000000;
 
     if (ro_session->event_type != pending) {
-        used = rint((get_current_time_micro() - ro_session->last_event_timestamp)/(float)1000000);
+        used = rint((stop_time - ro_session->last_event_timestamp) / (float) 1000000);
+        LM_DBG("Final used number of seconds for session is %ld\n", used);
+    }
+
+    LM_DBG("Call started at %ld and ended at %ld and lasted %d seconds and so far we have billed for %ld seconds\n", ro_session->start_time, stop_time,
+            actual_time_seconds, ro_session->billed + used);
+    if (ro_session->billed + used < actual_time_seconds) {
+        LM_DBG("Making adjustment by adding %ld seconds\n", actual_time_seconds - (ro_session->billed + used));
+        used += actual_time_seconds - (ro_session->billed + used);
     }
 
     counter_add(ims_charging_cnts_h.billed_secs, (int)used);
diff --git a/modules/ims_charging/ro_timer.c b/modules/ims_charging/ro_timer.c
index 40f3c42..efcc5cc 100644
--- a/modules/ims_charging/ro_timer.c
+++ b/modules/ims_charging/ro_timer.c
@@ -380,6 +380,7 @@ void resume_ro_session_ontimeout(struct interim_ccr *i_req) {
 void ro_session_ontimeout(struct ro_tl *tl) {
     time_t now, call_time;
     long used_secs;
+	int adjustment;
 
     LM_DBG("We have a fired timer [p=%p] and tl=[%i].\n", tl, tl->timeout);
 
@@ -419,6 +420,12 @@ void ro_session_ontimeout(struct ro_tl *tl) {
             used_secs = rint((now - ro_session->last_event_timestamp) / (float) 1000000);
             call_time = rint((now - ro_session->start_time) / (float) 1000000);
 
+			if ((used_secs + ro_session->billed) < (call_time)) {
+				adjustment = call_time - (used_secs + ro_session->billed);
+				LM_DBG("Making adjustment for Ro interim timer by adding %d seconds\n", adjustment);
+				used_secs += adjustment;
+			}
+			
             counter_add(ims_charging_cnts_h.billed_secs, used_secs);
 
             if (ro_session->callid.s != NULL
@@ -444,6 +451,7 @@ void ro_session_ontimeout(struct ro_tl *tl) {
                 // Apply for more credit.
                 //
                 // The function call will return immediately and we will receive the reply asynchronously via a callback
+				ro_session->billed += used_secs;
                 send_ccr_interim(ro_session, (unsigned int) used_secs, interim_request_credits);
                 return;
             } else {




More information about the sr-dev mailing list