Example #1
0
def create_monitor_response(imsi,
                            m_key,
                            total_quota,
                            level,
                            action=UsageMonitoringCredit.CONTINUE,
                            success=True):
    """
    Create a UsageMonitoringUpdateResponse with some useful defaults
    Args:
        imsi (string): subscriber id
        m_key (string): monitoring key
        quota (int): number of bytes to return
        level (MonitoringLevel): session level or rule level
        action (UsageMonitoringCredit.Action): action to take with response,
            defaults to CONTINUE
        success (bool): True if the update was successful
    """
    return UsageMonitoringUpdateResponse(
        success=success,
        sid=imsi,
        credit=UsageMonitoringCredit(
            monitoring_key=m_key,
            granted_units=GrantedUnits(total=CreditUnit(is_valid=True,
                                                        volume=total_quota), ),
            level=level,
            action=action),
    )
Example #2
0
 def _get_max_granted_units(self) -> GrantedUnits:
     """ Get an arbitrarily large amount of granted credit """
     return GrantedUnits(
         total=CreditUnit(
             is_valid=True,
             volume=100 * 1024 * 1024 * 1024,  # 100 GiB
         ),
         rx=CreditUnit(
             is_valid=True,
             volume=50 * 1024 * 1024 * 1024,  # 50 GiB
         ),
         tx=CreditUnit(
             is_valid=True,
             volume=50 * 1024 * 1024 * 1024,  # 50 GiB
         ),
     )
Example #3
0
def create_update_response(
    imsi,
    charging_key,
    total_quota,
    is_final=False,
    success=True,
):
    """
    Create a CreditUpdateResponse with some useful defaults
    Args:
        imsi (string): subscriber id
        charging_key (int): rating group
        quota (int): number of bytes to return
        is_final (bool): True if these are the last credits to return
        success (bool): True if the update was successful
    """
    return CreditUpdateResponse(
        success=success,
        sid=imsi,
        charging_key=charging_key,
        credit=ChargingCredit(
            granted_units=GrantedUnits(total=CreditUnit(is_valid=True,
                                                        volume=total_quota), ),
            is_final=is_final,
        ),
    )