> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/smc/3.15/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/smc/3.15/config/aaa/charging/rf.md).

# Rf Offline Charging Configuration

## Overview

Rf is the Diameter interface used for offline charging in 3GPP networks, specified in 3GPP TS 32.299. SMC sends Accounting-Request (ACR) messages to a Charging Gateway Function (CGF) or charging system, which generates CDRs (Charging Data Records) for billing.

Offline charging allows service delivery without real-time credit checks. Usage information is collected during the session and processed later for billing.

References:
- 3GPP TS 32.299 - Diameter charging applications
- 3GPP TS 32.251 - Packet Switched (PS) domain charging
- [Diameter Configuration](https://docs.cennso.com/components/smc/3.15/config/aaa/diameter-concepts.md) - Diameter transport configuration
- [Charging Overview](https://docs.cennso.com/components/smc/3.15/config/aaa/charging/overview.md) - Charging concepts and triggers

## Basic Configuration

Enable Rf and configure whether to use common Diameter settings:

```yaml
aaa:
  rf:
    enabled: true
    standalone: false  # Use common settings from aaa.oss
```

When `standalone` is `false`, Rf uses Diameter transport settings from `aaa.oss` (see [Diameter Configuration](https://docs.cennso.com/components/smc/3.15/config/aaa/diameter-concepts.md)).

When `standalone` is `true`, configure Rf-specific settings:

```yaml
aaa:
  rf:
    enabled: true
    standalone: true
    destinations:
      - addr: "10.1.2.100"
        port: 3868
    destinationRealm: "cgf.example.com"
    originFqdn: "pgw1.example.com"
    originRealm: "example.com"
```

## Network Configuration

Rf can use common network settings or dedicated network configuration.

### Using Common Network Settings

```yaml
networking:
  oss:
    interface: "eth0"
    ipv4:
      addr: "192.168.1.10"
    mtu: 1500

aaa:
  rf:
    enabled: true
    standalone: false
```

### Using Separate Network Settings

Rf does not have separate network settings. It always uses `networking.oss`. For separate network configuration, use Ro interface settings (see [Ro Configuration](https://docs.cennso.com/components/smc/3.15/config/aaa/charging/ro.md)).

## Accounting Phases

Rf supports three accounting phases:

### Accounting-Start

Sent when a user session is established. Contains initial session information:
- User identity (IMSI, MSISDN)
- Session start time
- Network context (PLMN, location, RAT type)
- IP address allocation
- QoS parameters

Automatically enabled when `aaa.rf.enabled` is `true`.

### Accounting-Interim

Sent periodically during an active session. Contains cumulative usage information:
- Data volume (uplink and downlink)
- Session duration
- Current location
- Current QoS

Interim interval controlled by `aaa.acctInterimInterval`:

```yaml
aaa:
  acctInterimInterval: 3600  # Send interim every 3600 seconds (1 hour)
  rf:
    enabled: true
```

Set to `null` to disable interim records:

```yaml
aaa:
  acctInterimInterval: null  # No interim records
```

> [!CAUTION]
> If RADIUS Stop or Interim accounting are enabled, `acctInterimInterval` cannot be `null`.

### Accounting-Stop

Sent when a user session terminates. Contains final usage information:
- Final data volume
- Total session duration
- Termination cause
- Final location

Automatically enabled when `aaa.rf.enabled` is `true`.

## Connection Monitoring

Monitor Rf connections using the `diameter_connections` metric with label `svc="ergw_rf"`.

**Example Prometheus query:**

```promql
diameter_connections{svc="ergw_rf"}
```

When the metric shows 0, no Rf connections are active.

## CDF failure handling

SMC handles CDF failures based on the Diameter Result-Code and transport state. Throughout this section, *answer* refers to a Diameter Accounting-Answer (ACA), the response to an Accounting-Request (ACR). The following behavior applies to both real CDF answers and synthetic answers injected by the transport failure options described below:

- **Success (2xxx):** charging data cleared; session continues.
- **`UNABLE_TO_DELIVER` (3002) or `TOO_BUSY` (3004):** charging data retained; session continues, subject to the `max_pending_data` cap.
- **Any other Result-Code:** session torn down.

A rejected or timed-out ACR-Initial aborts GTP session creation with cause `system_failure`.

### Transport failure options

Four Helm values control the behavior when the CDF is unreachable or a request times out.

| Helm value | Type | Description |
|---|---|---|
| `aaa.rf.answers` | list | Named synthetic ACA responses. Each entry has a `name` and an `avps` map (including `Result-Code`). |
| `aaa.rf.answer_if_down` | object | Per-request-state action when the CDF is unreachable. Keys: `initial` (ACR-Start) and `update` (ACR-Interim). Values: a name from `answers`, or `reject`. |
| `aaa.rf.answer_if_timeout` | object | Per-request-state action when an ACR times out. Same structure as `answer_if_down`. |
| `aaa.rf.max_pending_data` | integer | Cap on accumulated charging data count per session. Bounds memory growth during prolonged CDF outages. |

`answer_if_down` and `answer_if_timeout` accept separate settings for each request state because the impact differs: a failure during session creation (`initial`) is typically fatal, whilst a failure during an interim update (`update`) may be tolerable for a limited time. ACR-Stop is always best-effort and does not use these settings.

When `answer_if_down` or `answer_if_timeout` is set, SMC injects the referenced synthetic answer instead of treating the transport failure as an immediate error. The Result-Code in the synthetic answer then follows the same Result-Code semantics described at the start of this section.

When `max_pending_data` is set and the accumulated service data container and traffic data volume count exceeds the configured value, SMC tears down the session regardless of the Result-Code.

The Prometheus gauge `ergw_aaa_rf_queued_containers` (labels `svc`, `kind`) reports the current number of buffered Rf accounting containers — Service-Data-Containers (`sdc`), Traffic-Data-Volumes (`tdv`), and Secondary-RAT-Usage-Data-Reports (`sec_rat`) — summed across active sessions. Watch it during a CDF outage to size `max_pending_data` against actual buffering rates rather than guessing. See [Diameter metrics](https://docs.cennso.com/components/smc/3.15/observability/metrics.md#diameter-metrics) for the full metric description.

#### Example: reject sessions when CDF is down, keep sessions on timeout

```yaml
aaa:
  rf:
    enabled: true
    answers:
      - name: "CDF-Down-Reject"
        avps:
          Result-Code: 5012
      - name: "CDF-Timeout-Hold"
        avps:
          Result-Code: 3002
    answer_if_down:
      initial: "reject"
      update: "CDF-Down-Reject"
    answer_if_timeout:
      initial: "reject"
      update: "CDF-Timeout-Hold"
    max_pending_data: 100
```

In this configuration:
- New sessions are rejected when the CDF is down or an ACR times out.
- Existing sessions continue during timeouts (with charging data retained), but SMC tears them down after 100 accumulated data records or when the CDF returns a permanent error.
- Existing sessions are torn down immediately when the CDF is unreachable, because Result-Code 5012 is outside the 2xxx/3002/3004 keep-alive range.

> [!CAUTION]
> Without `max_pending_data` configured, the 3002/3004 keep-alive path retains charging data in memory indefinitely. Configure a cap appropriate for your deployment to bound per-session memory growth during extended CDF outages.

## Charging Triggers

Rf offline charging generates CDRs based on triggers. See [Charging Overview](https://docs.cennso.com/components/smc/3.15/config/aaa/charging/overview.md) for detailed trigger configuration.

**CDR generation triggers:**
- ms-time-zone-change
- rat-change
- sgsn-sgw-change
- sgsn-sgw-plmn-id-change

**Container update triggers:**
- cgi-sai-change
- ecgi-change
- qos-change
- rai-change
- tai-change
- tariff-switch-change
- user-location-info-change

## PCC Rule Integration

Offline charging is enabled per PCC rule. Configure rules with `offlineEnabled: true`:

```yaml
aaa:
  applicationDetection:
    rules:
      postpaid-data:
        type: classic
        precedence: 100
        meteringMethod: 1          # VOLUME
        offlineEnabled: true       # Enable offline charging
        onlineEnabled: false
        ratingGroup: 2000
        additionalSDF:
          - "permit out ip from any to assigned"
```

Multiple rules can share the same rating group for aggregated billing:

```yaml
rules:
  web-traffic:
    ratingGroup: 1000
    offlineEnabled: true
  
  video-traffic:
    ratingGroup: 1000  # Same rating group
    offlineEnabled: true
```

## Example Configurations

### Basic Rf with Common Settings

```yaml
aaa:
  acctInterimInterval: 3600
  
  oss:
    interface: "eth0"
    ipv4:
      addr: "192.168.1.10"
    mtu: 1500
    destinations:
      - addr: "192.168.1.100"
        port: 3868
    destinationRealm: "cgf.example.com"
    originFqdn: "pgw1.example.com"
    originRealm: "example.com"
  
  rf:
    enabled: true
    standalone: false
    transportType: "tcp"
    transportOpts:
      reuseaddr: true
      recbuf: 1024
      sndbuf: 1024
      nodelay: true
  
  applicationDetection:
    rules:
      default-postpaid:
        type: classic
        precedence: 1000
        meteringMethod: 1
        offlineEnabled: true
        ratingGroup: 1000
        additionalSDF:
          - "permit out ip from any to assigned"
```

### Rf with No Interim Records

```yaml
aaa:
  acctInterimInterval: null  # No interim records
  
  rf:
    enabled: true
    standalone: false
  
  applicationDetection:
    rules:
      simple-postpaid:
        type: classic
        precedence: 500
        meteringMethod: 1
        offlineEnabled: true
        ratingGroup: 5000
        additionalSDF:
          - "permit out ip from any to assigned"
```

> [!NOTE]
> This configuration only sends Accounting-Start and Accounting-Stop messages, not interim updates.

### Rf with Standalone Configuration

```yaml
aaa:
  acctInterimInterval: 1800
  
  rf:
    enabled: true
    standalone: true
    destinations:
      - addr: "10.5.6.100"
        port: 3868
      - addr: "10.5.6.101"
        port: 3868
    destinationRealm: "charging.example.com"
    originFqdn: "pgw1.node1.example.com"
    originRealm: "node1.example.com"
    transportType: "sctp"
    transportOpts:
      reuseaddr: true
      recbuf: 2048
      sndbuf: 2048
      unordered: true
  
  applicationDetection:
    rules:
      postpaid-service:
        type: classic
        precedence: 200
        meteringMethod: 2  # DURATION_VOLUME
        offlineEnabled: true
        ratingGroup: 3000
        additionalSDF:
          - "permit out ip from any to assigned"
```

### Multiple Rating Groups

```yaml
aaa:
  acctInterimInterval: 3600
  
  rf:
    enabled: true
    standalone: false
  
  applicationDetection:
    rules:
      basic-data:
        type: classic
        precedence: 300
        meteringMethod: 1
        offlineEnabled: true
        ratingGroup: 1000
        additionalSDF:
          - "permit out ip from any to assigned"
      
      premium-web:
        type: classic
        precedence: 100
        meteringMethod: 1
        offlineEnabled: true
        ratingGroup: 2000
        additionalSDF:
          - "permit out tcp from any to assigned 443"
      
      video-streaming:
        type: adf
        precedence: 50
        meteringMethod: 1
        offlineEnabled: true
        ratingGroup: 3000
```

## Troubleshooting

### No Rf Connection

**Symptom:** Metric `diameter_connections{svc="ergw_rf"}` shows 0.

**Possible causes:**
- CGF/charging system unreachable
- Diameter transport misconfiguration
- Firewall blocking port 3868

**Solution:**

1. Verify Diameter transport configuration (see [Diameter Configuration](https://docs.cennso.com/components/smc/3.15/config/aaa/diameter-concepts.md))

2. Check network connectivity:
   ```bash
   kubectl exec {POD_NAME} -- ping {CGF_ADDRESS}
   ```

3. Review SMC logs for Rf connection errors:
   ```bash
   kubectl logs {POD_NAME} | grep -i "ergw_rf"
   ```

4. Verify CGF/charging system is running and accepting connections

### Memory Growth

**Symptom:** SMC memory usage increases continuously when Rf connection is down.

**Cause:** Charging data is queued in memory while Rf is unavailable.

**Solution:**

1. Restore Rf connectivity immediately

2. Monitor memory usage:
   ```promql
   container_memory_usage_bytes{pod=~"smc-.*"}
   ```

3. If memory continues to grow dangerously, consider restarting SMC:
   ```bash
   kubectl rollout restart deployment/smc
   ```

> [!IMPORTANT]
> Restarting SMC during an Rf outage results in loss of queued offline charging records.

### No CDRs Generated

**Symptom:** CGF receives no CDRs despite active sessions.

**Possible causes:**
- `aaa.rf.enabled` is `false`
- No rules have `offlineEnabled: true`
- Sessions do not match any offline-enabled rules

**Solution:**

1. Verify Rf is enabled:
   ```yaml
   rf:
     enabled: true
   ```

2. Verify at least one rule has offline charging enabled:
   ```yaml
   rules:
     {RULE_NAME}:
       offlineEnabled: true
       ratingGroup: 1000
   ```

3. Verify rules are activated by checking session logs

4. Verify sessions match rule flow descriptions

### Interim Records Not Sent

**Symptom:** Start and Stop records are received, but no interim records.

**Possible causes:**
- `acctInterimInterval` is `null`
- `acctInterimInterval` is larger than session duration
- Sessions terminate before interim interval expires

**Solution:**

1. Configure interim interval:
   ```yaml
   acctInterimInterval: 3600  # 1 hour
   ```

2. Reduce interval for testing:
   ```yaml
   acctInterimInterval: 300  # 5 minutes
   ```

3. Verify sessions last longer than the interim interval

4. Check SMC logs for interim accounting messages

### Wrong Rating Group in CDRs

**Symptom:** CDRs contain unexpected rating group values.

**Possible causes:**
- Multiple rules match the same traffic
- Wrong rule has higher precedence
- `offlineRatingGroup` overrides `ratingGroup`

**Solution:**

1. Review rule precedence - lower values are evaluated first:
   ```yaml
   high-priority-rule:
     precedence: 50   # Evaluated first
   
   low-priority-rule:
     precedence: 200  # Evaluated later
   ```

2. Check for `offlineRatingGroup` overrides:
   ```yaml
   mixed-rule:
     ratingGroup: 1000
     offlineRatingGroup: 1001  # This value is used for offline charging
   ```

3. Verify flow descriptions match intended traffic

4. Test with simple catch-all rules to isolate the issue
