> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/smc/latest/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/latest/guides/aaa/charging/ro.md).

# Ro (Gy) Online Charging Configuration

## Overview

Ro is the Diameter Credit-Control Application running over the 3GPP Gy reference point for online charging in 3GPP networks. It is specified in 3GPP TS 32.299. SMC sends Credit-Control-Request (CCR) messages to the Online Charging System (OCS), which grants quota based on subscriber credit availability.

Online charging verifies credit before allowing service delivery, making it suitable for prepaid and budget-controlled accounts.

> **Note:** While technically named "Ro" (the Diameter application), this interface is commonly referred to as "Gy" in 3GPP terminology, which is the reference point name users typically search for.

References:
- 3GPP TS 32.299 - Diameter charging applications
- [RFC 4006](https://www.rfc-editor.org/rfc/rfc4006.html) - Diameter Credit-Control Application
- [Diameter Configuration](https://docs.cennso.com/components/smc/latest/guides/aaa/diameter-concepts.md) - Diameter transport configuration
- [Charging Overview](https://docs.cennso.com/components/smc/latest/guides/aaa/charging/overview.md) - Charging concepts

## Basic Configuration

Enable Ro and configure whether to use common Diameter settings:

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

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

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

```yaml
aaa:
  ro:
    enabled: true
    standalone: true
    destinations:
      - addr: "10.2.3.100"
        port: 3868
    destinationRealm: "ocs.example.com"
    originFqdn: "pgw1.example.com"
    originRealm: "example.com"
```

## Network Configuration

Ro 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:
  ro:
    enabled: true
    standalone: false
```

### Using Separate Network Settings

Configure dedicated network settings for Ro:

```yaml
networking:
  ro:
    interface: "bond1"
    ipv4:
      addr: "10.5.6.10"
    mtu: 9000

aaa:
  ro:
    enabled: true
    standalone: true
    destinations:
      - addr: "10.5.6.100"
        port: 3868
    destinationRealm: "ocs.example.com"
    originFqdn: "pgw1.example.com"
    originRealm: "example.com"
```

## Credit-Control Procedures

Ro implements three credit-control procedures:

### CCR-Initial / CCA-Initial

Sent when a user session requiring online charging is established.

**Purpose:**
- Request initial quota from OCS
- Provide session context (IMSI, MSISDN, service details)
- Receive granted quota (volume, time, or both)

**OCS response (CCA-Initial):**
- Granted-Service-Unit (volume and/or time)
- Validity-Time (quota expiration)
- Result-Code (success or failure)

If the OCS denies credit (for example, insufficient balance), the session is not established or the service is restricted.

### CCR-Update / CCA-Update

Sent when granted quota is nearly exhausted or when session parameters change.

**Triggers:**
- Quota threshold reached (for example, 80% consumed)
- Quota expiration approaching
- Service-level changes
- Location or RAT type changes

**Purpose:**
- Report consumed quota
- Request additional quota
- Update session information

**OCS response (CCA-Update):**
- Additional granted quota
- Quota refill
- Service termination instruction

### CCR-Terminate / CCA-Terminate

Sent when the user session terminates.

**Purpose:**
- Report final consumed quota
- Close charging context
- Final balance update

**OCS response (CCA-Terminate):**
- Acknowledgement
- Final cost (informational)

## PCC Rule Integration

Online charging is enabled per PCC rule. Configure rules with `onlineEnabled: true`:

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

Multiple rules can use the same rating group, or use separate rating groups for different services:

```yaml
rules:
  prepaid-basic:
    ratingGroup: 1000
    onlineEnabled: true
  
  prepaid-premium:
    ratingGroup: 2000  # Different rating group = different rate
    onlineEnabled: true
```

## OCS Free Feature

OCS Free allows user sessions to continue with predefined quota when the OCS is unavailable or unresponsive. This prevents service disruption during OCS outages.

### Enabling OCS Free

```yaml
aaa:
  ro:
    enabled: true
    ocsFree:
      enabled: true
      ccTimeMin: 3600    # Minimum granted time (seconds)
      ccTimeMax: 7200    # Maximum granted time (seconds)
```

When enabled, SMC uses predefined responses in these conditions:
- OCS is unreachable (connection down)
- Request times out
- Rate limit is exceeded

### OCS Free Behaviour

When OCS Free activates, SMC generates a synthetic CCA response:

```yaml
Result-Code: 2001
Multiple-Services-Credit-Control:
  - Envelope-Reporting: 0
    Granted-Service-Unit:
      CC-Time: <random value between ccTimeMin and ccTimeMax>
    Rating-Group: <from rule configuration>
    Result-Code: 2001
    Time-Quota-Threshold: 60
```

**Key characteristics:**
- One entry per rule with `onlineEnabled: true`
- Granted time is randomised between `ccTimeMin` and `ccTimeMax`
- Rating group comes from rule configuration (`onlineRatingGroup` or `ratingGroup`)
- No volume quota is granted (time-based only)
- When granted quota expires, the session terminates without further OCS communication

> [!CAUTION]
> OCS Free grants quota without real credit checks. Use only for temporary OCS outages. Sessions may exceed subscriber credit limits during OCS Free operation.

### OCS Free Configuration Parameters

The following table lists the OCS Free configuration parameters and their types:

| Parameter | Type | Description |
|---|---|---|
| enabled | boolean | Enable OCS Free feature |
| ccTimeMin | integer | Minimum granted time in seconds |
| ccTimeMax | integer | Maximum granted time in seconds |

**Recommended values:**
- `ccTimeMin: 3600` - 1 hour minimum
- `ccTimeMax: 7200` - 2 hours maximum

Randomisation prevents all sessions from expiring simultaneously when OCS recovers.

## Example Configurations

### Basic Ro with Common Settings

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

### Ro with OCS Free

```yaml
aaa:
  ro:
    enabled: true
    standalone: false
    ocsFree:
      enabled: true
      ccTimeMin: 1800   # 30 minutes
      ccTimeMax: 3600   # 60 minutes
  
  applicationDetection:
    rules:
      prepaid-data:
        type: classic
        precedence: 100
        meteringMethod: 1
        onlineEnabled: true
        ratingGroup: 2000
        additionalSDF:
          - "permit out ip from any to assigned"
```

### Ro with Separate Network

```yaml
networking:
  ro:
    interface: "bond1"
    ipv4:
      addr: "10.5.6.10"
    mtu: 9000

aaa:
  ro:
    enabled: true
    standalone: true
    destinations:
      - addr: "10.5.6.200"
        port: 3868
      - addr: "10.5.6.201"
        port: 3868
    destinationRealm: "ocs.example.com"
    originFqdn: "pgw1.node1.example.com"
    originRealm: "node1.example.com"
    transportType: "sctp"
    transportOpts:
      reuseaddr: true
      recbuf: 4096
      sndbuf: 4096
      unordered: true
    ocsFree:
      enabled: true
      ccTimeMin: 3600
      ccTimeMax: 7200
  
  applicationDetection:
    rules:
      prepaid-service:
        type: classic
        precedence: 50
        meteringMethod: 1
        onlineEnabled: true
        ratingGroup: 5000
        additionalSDF:
          - "permit out ip from any to assigned"
```

### Multiple Online Services

```yaml
aaa:
  ro:
    enabled: true
    standalone: false
    ocsFree:
      enabled: true
      ccTimeMin: 3600
      ccTimeMax: 7200
  
  applicationDetection:
    rules:
      prepaid-basic:
        type: classic
        precedence: 300
        meteringMethod: 1
        onlineEnabled: true
        ratingGroup: 1000
        additionalSDF:
          - "permit out ip from any to assigned"
      
      prepaid-video:
        type: adf
        precedence: 100
        meteringMethod: 1
        onlineEnabled: true
        ratingGroup: 3000
      
      prepaid-premium:
        type: classic
        precedence: 50
        meteringMethod: 2  # DURATION_VOLUME
        onlineEnabled: true
        ratingGroup: 5000
        additionalSDF:
          - "permit out ip from any to assigned"
```

### Hybrid Charging (Online + Offline)

```yaml
aaa:
  ro:
    enabled: true
  
  rf:
    enabled: true
  
  applicationDetection:
    rules:
      hybrid-charging:
        type: classic
        precedence: 100
        meteringMethod: 1
        onlineEnabled: true
        offlineEnabled: true
        ratingGroup: 4000
        onlineRatingGroup: 4001   # Different rating groups
        offlineRatingGroup: 4002
        additionalSDF:
          - "permit out ip from any to assigned"
```

## Troubleshooting

### Sessions Rejected by OCS

**Symptom:** Sessions fail to establish with insufficient credit errors.

**Cause:** OCS reports subscriber has insufficient balance.

**Solution:**

1. Verify subscriber balance in OCS

2. Check OCS policies for the subscriber

3. Review CCA result code in SMC logs:
   - 4xxx = Client error (for example, invalid request)
   - 5xxx = Server error (for example, OCS internal error)

4. Check OCS logs for rejection reason

### OCS Not Reachable

**Symptom:** All sessions fail with connection errors.

**Possible causes:**
- OCS server down
- Network connectivity issues
- Firewall blocking port 3868

**Solution:**

1. Verify OCS connectivity (see [Diameter Configuration](https://docs.cennso.com/components/smc/latest/guides/aaa/diameter-concepts.md))

2. Check if OCS Free is enabled and activating:
   ```yaml
   ro:
     ocsFree:
       enabled: true
   ```

3. Review SMC logs for Ro connection errors

4. Verify OCS service status

### OCS Free Not Activating

**Symptom:** Sessions fail when OCS is down despite OCS Free being enabled.

**Possible causes:**
- OCS Free not enabled
- Configuration error in `ocsFree` section
- No rules have `onlineEnabled: true`

**Solution:**

1. Verify OCS Free is enabled:
   ```yaml
   ro:
     ocsFree:
       enabled: true
       ccTimeMin: 3600
       ccTimeMax: 7200
   ```

2. Verify at least one rule has online charging enabled:
   ```yaml
   rules:
     {RULE_NAME}:
       onlineEnabled: true
   ```

3. Check SMC logs for OCS Free activation messages

4. Test OCS connectivity issues (stop OCS temporarily)

### Quota Exhausted Too Quickly

**Symptom:** Sessions terminate frequently due to quota exhaustion.

**Possible causes:**
- OCS grants small quota
- High data usage
- Quota threshold too high (causing frequent re-authorisation)

**Solution:**

1. Check OCS quota grant policies

2. Review typical usage patterns for the service

3. Consider increasing quota threshold in OCS configuration

4. Check for traffic loops or unusual traffic patterns

### Wrong Rating Group in Ro Messages

**Symptom:** CCR messages contain unexpected rating group values.

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

**Solution:**

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

2. Check for `onlineRatingGroup` overrides:
   ```yaml
   hybrid-rule:
     ratingGroup: 1000
     onlineRatingGroup: 1001  # This value used for online charging
   ```

3. Verify flow descriptions match intended traffic

4. Check SMC logs for rule activation details

### OCS Free Quota Too Short

**Symptom:** Sessions terminate quickly during OCS Free operation.

**Cause:** `ccTimeMin` and `ccTimeMax` values are too small.

**Solution:**

Increase OCS Free time grants:

```yaml
ro:
  ocsFree:
    enabled: true
    ccTimeMin: 7200    # 2 hours (was 1 hour)
    ccTimeMax: 14400   # 4 hours (was 2 hours)
```

> [!TIP]
> Balance OCS Free quota with business risk. Longer quotas provide better service continuity but increase revenue risk during OCS outages.

### Sessions Not Using OCS Free

**Symptom:** Sessions fail when OCS is unavailable despite OCS Free configuration.

**Possible causes:**
- Connection to OCS not detected as down (slow timeout)
- Rate limiting not configured correctly
- OCS responding with errors instead of timing out

**Solution:**

1. Verify connection monitoring detects OCS failures

2. Configure rate limiting to trigger OCS Free faster:
   ```yaml
   diameter:
     rateLimits:
       peers:
         - addr: "{OCS_ADDRESS}"
           rate: 1000
           outstanding_requests: 5000
   ```

3. Check OCS response codes - 5xxx errors should trigger OCS Free

4. Review timeout settings (fixed at 5000 milliseconds)

> [!NOTE]
> OCS Free activates when OCS is unreachable, times out, or rate limit is exceeded. It does not activate for OCS rejections (insufficient credit).
