Module ocs_rating

This library module implements utility functions for handling rating in the ocs application.

Copyright © 2016 - 2026 SigScale Global Inc.

Description

This library module implements utility functions for handling rating in the ocs application.

Data Types

aka_cred()

aka_cred() = #aka_cred{k = binary(), opc = binary(), dif = integer()}

bucket()

bucket() = #bucket{id = string() | undefined | '_' | '$1', name = string() | undefined | '_', start_date = pos_integer() | undefined | '_', end_date = pos_integer() | undefined | '_', status = bucket_status() | undefined | '_', remain_amount = integer() | '_', attributes = bucket_attributes() | '_', units = octets | cents | seconds | messages | undefined | '_', price = string() | '_', product = [ProdRef::term()] | '_', last_modified = tuple() | undefined | '_'}

bucket_attributes()

bucket_attributes() = #{bucket_type := normal | session, from_bucket => [bucket_source()], reservations => reservations()}

bucket_source()

bucket_source() = #{id := string(), amount := pos_integer(), unit_size := pos_integer(), unit_price := pos_integer(), expire := pos_integer() | undefined}

bucket_status()

bucket_status() = active | expired | suspended

pla_ref()

pla_ref() = #pla_ref{id = string() | undefined | '_', href = string() | undefined | '_', name = string() | undefined | '_', class_type = string() | undefined | '_', base_type = string() | undefined | '_', schema = string() | undefined | '_', ref_type = string() | undefined | '_'}

product_price_type()

product_price_type() = recurring | one_time | usage | tariff | pla_ref()

quantity()

quantity() = #quantity{amount = integer(), units = atom() | string()}

range()

range() = #range{lower = quantity(), upper = quantity()}

rate()

rate() = #rate{numerator = quantity(), denominator = quantity()}

recur_period()

recur_period() = hourly | daily | weekly | monthly | yearly

reservation()

reservation() = #{ts := pos_integer(), debit := non_neg_integer(), reserve := non_neg_integer(), service_id => non_neg_integer(), charging_key => non_neg_integer()}

reservations()

reservations() = #{SesssionID::list() => reservation()}

service_status()

service_status() = feasibilityChecked | designed | reserved | active | inactive | terminated

Function Index

rate/13Handle rating and balance management for used and reserved unit amounts.
charge/11Handle balance management for used and reserved unit amounts.
authorize/8Authorize access request.
session_attributes/1Extract RADIUS session related attributes.
update_session/7*Perform debit and reservation for a session.
charge_session/6*Peform final charging for a session.
charge_event/3*Peform immediate event charging (IEC).
convert/10*Convert cents to Type bucket(s) of Size.
remove_session/2*Remove session identification attributes set from active sessions list.
add_session/2*Add session identification attributes set to active sessions list.
get_session_id/1*Get the session identifier value.
split_by_price/1*Split out buckets with price name.
sort_by_age/1*Sort Buckets with soonest to expire first.
sort_from_bucket/1*Sort BucketSource with soonest to expire first.
price_units/3*Calculate total size and price.
refund/4*Refund unused reservations.
get_final/5*Get total debited and remaining amounts, refund and remove all reservations, for session.
make_lm/0*
make_id/1*
send_notifications/1*
notify_accumulated_balance/1*
accumulated_balance/2*
accumulated_balance/3*
build_acc/6*

Function Details

rate/13

rate(Protocol, ServiceType, ServiceId, ChargingKey, ServiceNetwork, SubscriberIDs, Timestamp, Address, Direction, Flag, DebitAmounts, ReserveAmounts, SessionAttributes) -> Result

Handle rating and balance management for used and reserved unit amounts.

Subscriber balance buckets are permanently reduced by the amount in DebitAmounts and bucket reservations are made of the amounts in ReserveAmounts. The subscribed Product Offering provides one or more Product Offering Price (POP) used to rate the service usage.

Centralized Unit Determination

If ReserveAmounts is an empty list, and Flag is initial, interim or event, the UnitType and Amount are determined by applicable POP.

Decentralized Unit Determination

If ReserveAmounts is a non empty list, and Flag is initial, interim or event, the list provides one or more alternate measures of service with different UnitType allowing the applicable POP to determine which UnitType is used, with the Amount explicitly provided.

Immediate Event Charging (IEC)

If Flag is event then DebitAmounts should be an empty list and centralized, or decentralized, unit determination on ReserveAmounts provides a UnitType and Amount to be immediately debited (without reservation).

If ReserveAmounts is undefined no reservation is performed.

The value of DebitAmounts is a list of one or more alternate measures of the service usage with different UnitType (i.e. octets and seconds) allowing the applied POP to determine the UnitType used for rating.

If successful returns {ok, Service, GrantedAmount} for initial and interim updates, {ok, Service, Rated} for final or {ok, Service, GrantedAmount, Rated} for event.

If subscriber's balance is insufficient to cover the DebitAmounts and ReserveAmounts returns {out_of_credit, RedirectServerAddress, SessionList} for initial or interim and {out_of_credit, RedirectServerAddress, SessionList, Rated} for final.

Returns {disabled, SessionList} if the subscriber is not enabled. The value of SessionList describes the known active sessions which should be disconnected.

A successful call with Flag value of initial starts a session which must eventually be released by another call with exactly the same SessionAttributes and a Flag value of final.

charge/11

charge(Protocol, Flag, SubscriberIDs, ServiceId, ChargingKey, ServiceNetwork, Address, Prices, DebitAmounts, ReserveAmounts, SessionAttributes) -> Result

Handle balance management for used and reserved unit amounts.

authorize/8

authorize(Protocol, ServiceType, SubscriberIDs, Password, Timestamp, Address, Direction, SessionAttributes) -> Result

Authorize access request.

If authorized returns attributes to be included in Access-Accept response.

When subscriber's product instance includes the radiusReserveSessionTime characteristic a reservation is attempted for the given value of seconds. A Session-Timeout attribute will be included with the actual reservation.

session_attributes/1

session_attributes(Attributes) -> SessionAttributes

Extract RADIUS session related attributes.

update_session/7 *

update_session(Type, Charge, Reserve, ServiceId, ChargingKey, SessionId, Buckets) -> Result

Perform debit and reservation for a session.

Finds reservations matching SessionId, ChargingKey and ServiceId.

Empty or expired buckets are removed when no session reservations remain.

Returns {Charged, Reserved, NewBuckets} where Charged is the total amount debited from bucket(s), Reserved is the total amount of quota reservation, and NewBuckets is the updated bucket list.

The Reserve amount is not additive, the Reserved amount is the new total reservation.

3GPP RS 32.299 6.3.8 Support of re-authorization: "New quota allocations [...] override any remaining held quota"

charge_session/6 *

charge_session(Type, Charge, ServiceId, ChargingKey, SessionId, Buckets) -> Result

Peform final charging for a session.

Returns {Charged, NewBuckets} where Charged is the total amount debited from the buckets and NewBuckets is the updated bucket list.

charge_event/3 *

charge_event(Type, Charge, Buckets) -> Result

Peform immediate event charging (IEC).

Returns {Charged, NewBuckets} where Charged is the total amount debited from the buckets and NewBuckets is the updated bucket list.

convert/10 *

convert(ProductId, Price, Type, UnitPrice, UnitSize, TotalSize, ServiceId, ChargingKey, SessionId, Buckets) -> Result

Convert cents to Type bucket(s) of Size.

Tops up existing bucket for session if found, otherwise creates session bucket(s) of Type.

remove_session/2 *

remove_session(SessionId, SessionList) -> NewSessionList

Remove session identification attributes set from active sessions list.

add_session/2 *

add_session(SessionAttributes, SessionList) -> SessionList

Add session identification attributes set to active sessions list.

get_session_id/1 *

get_session_id(SessionAttributes) -> SessionId

Get the session identifier value. Returns a list of Nrf/DIAMETER/RADIUS attributes.

split_by_price/1 *

split_by_price(Buckets) -> Result

Split out buckets with price name.

sort_by_age/1 *

sort_by_age(Buckets) -> Buckets

Sort Buckets with soonest to expire first.

sort_from_bucket/1 *

sort_from_bucket(FromBucket) -> FromBucket

Sort BucketSource with soonest to expire first.

price_units/3 *

price_units(Amount, UnitSize, UnitPrice) -> {TotalUnits, TotalPrice}

Calculate total size and price.

refund/4 *

refund(ServiceId, ChargingKey, SessionId, Buckets) -> Buckets

Refund unused reservations.

get_final/5 *

get_final(ServiceId, ChargingKey, SessionId, Refund, Buckets) -> Result

Get total debited and remaining amounts, refund and remove all reservations, for session.

make_lm/0 *

make_lm() -> any()

make_id/1 *

make_id(X1) -> any()

send_notifications/1 *

send_notifications(T) -> any()

notify_accumulated_balance/1 *

notify_accumulated_balance(AccBlance) -> any()

accumulated_balance/2 *

accumulated_balance(Buckets, ProdRef) -> any()

accumulated_balance/3 *

accumulated_balance(Buckets, ProdRef, X3) -> any()

build_acc/6 *

build_acc(Buckets, Name, Units, ProdRef, X5, AccBalance) -> any()


Generated by EDoc