Radius Interim Updates (alive)

147 views
Skip to first unread message

Tawanda C

unread,
Nov 2, 2021, 5:59:01 PM11/2/21
to CGRateS
Hello, 

I am trying to get Cgrates to update balance based on radius Alive (interim update) messages. However since the Octet fields in the radius packet  are incremental my balance depletion is not correct. Is there logic I can use to get the changes in (~*req.Acct-Input-Octets;~*req.Acct-Output-Octets) between Alive messages?  Is there a logic type for this? I have tried *usage_difference and *difference

<<Cgrates Radius Accounting>>

"id": "MktUpdate",
"tenant" : "WiFi",
"filters": ["*string:~*req.Acct-Status-Type:Interim-Update"],
"flags": ["*update", "*accounts", "*attributes", "*continue"],
"request_fields":[
          {"tag": "LastUsed", "path": "*cgreq.LastUsed", "type": "*sum",
"value": "~*req.Acct-Input-Octets;~*req.Acct-Output-Octets"},
----- 

Raw Radius Packet (1)

2021-11-02 23:19:06.328021 (7) Accounting-Request Id 211 ens18:X.X.X.122:59881 -> X.X.X.14:1813 +21.606
        User-Name = "wifidemo"
        Acct-Status-Type = Interim-Update
        Acct-Input-Octets = 1791946
        Acct-Output-Octets = 1735831

Raw Radius packet (2)

2021-11-02 23:19:06.328021 (7) Accounting-Request Id 211 ens18:X.X.X.122:59881 -> X.X.X.14:1813 +21.606
        User-Name = "wifidemo"
        Acct-Status-Type = Interim-Update
        Acct-Input-Octets = 2562242
        Acct-Output-Octets = 2483927

The data consumed between these two messages is (2562242+2483927) - (1791946+1735831) = 1,518,392

Thanks.

TC.

Ionut Boangiu

unread,
Nov 8, 2021, 5:01:12 AM11/8/21
to CGRateS
Hi TC,

One way you could retrieve the data consumed between two messages is by doing the following for each radius packet:
  •  initialize a temporary variable in which you store the sum of the input and output octets from the packet that is being processed at that moment;
  •  compute your desired value as a difference between the current sum from the previous step and the cached sum of the packet processed before this, if it exists;
  •  store the variable created in the first step in the cache, to help determine the difference when processing the next packet.

To make things clearer, I updated the request processor you provided:


"id": "MktUpdate",
"tenant" : "WiFi",
"filters": ["*string:~*req.Acct-Status-Type:Interim-Update"],
"flags": ["*update", "*accounts", "*attributes", "*continue"],
"request_fields":[
         // create the temporary variable with the octets sum (path should begin with *tmp since it can be discarded after every process)
        {"path": "*tmp.InputOutputSum", "type": "*sum", "value": "~*req.Acct-Input-Octets;~*req.Acct-Output-Octets"}, 
        // calculate the difference between this sum and the previous one if it exists. You can check this by using a filter of type "*exists"
        {"path": "*cgreq.Consumed", "type": "*difference", "value": "~*tmp.InputOutputSum;~*uch.PrevSum", "filters": ["*exists:~*uch.PrevSum:"]},
        // create a variable with the value of the current sum whose path begins with *uch, which means that it will be saved in cache, ready to be used when determining the next difference
        {"path": "*uch.PrevSum", "type": "*variable", "value": "~*tmp.InputOutputSum"} 
],
Reply all
Reply to author
Forward
0 new messages