> 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/policy/gx.md).

# Gx Policy Control Configuration

## Overview

Gx is the Diameter-based interface between the Policy and Charging Enforcement Function (PCEF) and the Policy and Charging Rules Function (PCRF), defined in 3GPP TS 29.212. Through Gx, the PCRF controls PCC (Policy and Charging Control) rules applied to user sessions.

SMC implements the PCEF role and communicates with an external PCRF via the Gx interface.

References:
- 3GPP TS 23.203 - Policy and charging control architecture
- 3GPP TS 29.212 - Gx reference point
- [Diameter Configuration](https://docs.cennso.com/components/smc/latest/guides/aaa/diameter-concepts.md) - Diameter transport configuration
- [PCC Rules](https://docs.cennso.com/components/smc/latest/guides/aaa/policy/pcc-rules.md) - PCC rule configuration

## Basic Configuration

Gx uses Diameter transport. Configure Diameter transport first (see [Diameter Configuration](https://docs.cennso.com/components/smc/latest/guides/aaa/diameter-concepts.md)), then enable Gx:

```yaml
aaa:
  gx:
    enabled: true
```

When `enabled` is `true`, SMC sends Credit-Control-Request (CCR) messages to the PCRF via Gx during session establishment, updates, and termination.

## Static Policy Provisioning

For testing or deployments without a PCRF, disable Gx and configure rules statically. When `aaa.gx.enabled` is `false`, the chart uses a built-in static handler that activates the rule base name configured under `aaa.applicationDetection.rulesBaseName`:

```yaml
aaa:
  gx:
    enabled: false  # Use built-in static handler

  applicationDetection:
    rulesBaseName: "m2mbase"  # Activated for all sessions
    rules:
      default-rule:
        type: classic
        precedence: 1000
        offlineEnabled: true
        ratingGroup: 1000
        additionalSDF:
          - "permit out ip from any to assigned"
```

This configuration:
- Disables dynamic Gx communication
- Activates the configured rule base for all sessions

## Gx Procedures

SMC implements three Gx procedures:

### CCR-Initial / CCA-Initial

Sent when a user session is established (for example, GTP Create Session Request or PFCP Session Establishment).

**Direction:** PCEF → PCRF

**Purpose:**
- Request initial policies for the session
- Provide session context (IMSI, APN, location, etc.)
- Receive PCC rules and QoS policies

**Example CCA-Initial response:**

```yaml
answers:
  - name: "Initial-Gx"
    avps:
      Result-Code: 2001
      Charging-Rule-Install:
        - Charging-Rule-Name: ["premium-service", "default-data"]
```

### CCR-Update / CCA-Update

Sent when session parameters change (for example,  location update, RAT type change, QoS modification).

**Direction:** PCEF → PCRF

**Purpose:**
- Inform PCRF of session changes
- Request updated policies
- Receive rule additions or removals

**Triggers for CCR-Update:**
- Location change (User-Location-Info)
- RAT type change (3GPP-RAT-Type)
- QoS change
- Bearer operation (addition/modification/deletion)
- Explicit policy update request

**Example CCA-Update response:**

```yaml
answers:
  - name: "Update-Gx"
    avps:
      Result-Code: 2001
      Charging-Rule-Install:
        - Charging-Rule-Name: ["roaming-rule"]
      Charging-Rule-Remove:
        - Charging-Rule-Name: ["premium-service"]
```

### CCR-Terminate / CCA-Terminate

Sent when a user session terminates (for example, GTP Delete Session Request or PFCP Session Deletion).

**Direction:** PCEF → PCRF

**Purpose:**
- Inform PCRF of session termination
- Close policy context
- Report final session information

**Example CCA-Terminate response:**

```yaml
answers:
  - name: "Terminate-Gx"
    avps:
      Result-Code: 2001
```

## PCRF-Initiated Updates

The PCRF can initiate policy updates by sending Re-Authorization-Request (RAR) messages to SMC.

**Direction:** PCRF → PCEF

**Purpose:**
- Install new rules
- Remove existing rules
- Modify QoS parameters

**SMC response:** Re-Authorization-Answer (RAA)

> [!NOTE]
> SMC supports PCRF-initiated policy updates via RAR/RAA exchange.

## Rule Installation Methods

The PCRF can install PCC rules using three methods:

### Installation by Rule Name

Reference a pre-configured rule in SMC:

```yaml
answers:
  - name: "Initial-Gx"
    avps:
      Result-Code: 2001
      Charging-Rule-Install:
        - Charging-Rule-Name: ["premium-service"]
```

The rule "premium-service" must exist in SMC configuration under `aaa.applicationDetection.rules`.

**Advantage:** Rules defined once in SMC, referenced by PCRF  
**Use case:** Standard service rules shared across subscribers

### Installation by Rule Base

Reference a collection of rules:

```yaml
answers:
  - name: "Initial-Gx"
    avps:
      Result-Code: 2001
      Charging-Rule-Install:
        - Charging-Rule-Base-Name: ["silver-tier"]
```

The rule base "silver-tier" must be configured in SMC under `aaa.applicationDetection.rulesBaseName`.

**Advantage:** Activate multiple rules with a single reference  
**Use case:** Service tier packages (bronze, silver, gold)

### Inline Rule Definition

Define the complete rule in the CCA message:

```yaml
answers:
  - name: "Initial-Gx"
    avps:
      Result-Code: 2001
      Charging-Rule-Install:
        - Charging-Rule-Definition:
            - Charging-Rule-Name: "dynamic-video"
              Rating-Group: [4000]
              Precedence: [75]
              Flow-Information:
                - Flow-Description: ["permit out ip from any to assigned"]
                  Flow-Direction: [1]
              Metering-Method: [1]
              Online: [1]
              Offline: [0]
```

The PCRF defines the rule completely, including flow descriptions, precedence, and charging parameters.

**Advantage:** Dynamic rule creation per subscriber  
**Use case:** Subscriber-specific rules, temporary rules

> [!TIP]
> Use inline rules when rules must vary per subscriber. Use rule names for common rules to reduce message size and simplify management.

## Rule Removal

Remove previously installed rules:

```yaml
answers:
  - name: "Update-Gx"
    avps:
      Result-Code: 2001
      Charging-Rule-Remove:
        - Charging-Rule-Name: ["premium-service", "video-stream"]
```

This removes both "premium-service" and "video-stream" rules from the session.

> [!NOTE]
> Rule removal applies to rules installed by name, base, or inline definition.

## Session Context AVPs

SMC sends session context information in CCR messages. The PCRF uses this information for policy decisions.

Key AVPs sent by SMC:

| AVP | Description |
|---|---|
| Subscription-Id | User identity (IMSI, MSISDN) |
| Framed-IP-Address | User's IPv4 address |
| Framed-IPv6-Prefix | User's IPv6 prefix |
| Called-Station-Id | APN or DNN |
| 3GPP-SGSN-Address | Serving gateway address |
| 3GPP-SGSN-MCC-MNC | Serving network identity |
| 3GPP-User-Location-Info | Cell/tracking area identity |
| 3GPP-RAT-Type | Radio access technology |
| QoS-Information | Requested QoS parameters |
| Bearer-Operation | Bearer establishment/modification/termination |

For a complete AVP list, see [Diameter Support](https://docs.cennso.com/components/smc/latest/reference/protocols/diameter.md#policy-control-via-gx).

## Application Mapping

The chart automatically generates the internal AAA procedure chain for Gx based on `aaa.gx.enabled`. When `enabled: true`, all three Gx procedures (CCR-Initial, CCR-Update, CCR-Terminate) are wired to the Diameter handler. No manual mapping configuration is needed or supported via Helm values.

## Example Configurations

### Dynamic Gx with Live PCRF

```yaml
aaa:
  gx:
    enabled: true

  oss:
    destinations:
      - addr: "10.1.2.100"
        port: 3868
    destinationRealm: "pcrf.example.com"
    originFqdn: "pgw1.example.com"
    originRealm: "example.com"
```

### Static Policy (Testing)

```yaml
aaa:
  gx:
    enabled: false

  applicationDetection:
    rulesBaseName: "default-base"
    rules:
      default-data:
        type: classic
        precedence: 1000
        meteringMethod: 1
        onlineEnabled: true
        ratingGroup: 1000
        additionalSDF:
          - "permit out ip from any to assigned"
```

### Static Policy with Multiple Rules

```yaml
aaa:
  gx:
    enabled: false

  applicationDetection:
    rulesBaseName: "standard-rules"
    rules:
      web-traffic:
        type: classic
        precedence: 100
        meteringMethod: 1
        onlineEnabled: true
        ratingGroup: 2000
        additionalSDF:
          - "permit out tcp from any to assigned 80"
          - "permit out tcp from any to assigned 443"

      general-traffic:
        type: classic
        precedence: 200
        meteringMethod: 1
        onlineEnabled: true
        ratingGroup: 2001
        additionalSDF:
          - "permit out ip from any to assigned"
```

### Inline Rule Definition (Static)

Inline rule definitions in static CCA answers can be used via the `configYaml` escape hatch for advanced deployments. See [chart configuration reference](https://docs.cennso.com/components/smc/latest/reference/chart-configuration.generated.md) for `configYaml`.

## Troubleshooting

### No Gx Communication

**Symptom:** CCR messages are not sent to PCRF.

**Possible causes:**
- `aaa.gx.enabled` is `false`
- Diameter connection to PCRF is down
- Gx procedures not mapped in application configuration

**Solution:**

1. Enable Gx:
   ```yaml
   gx:
     enabled: true
   ```

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

3. Verify `aaa.gx.enabled: true` is set (the chart maps procedures automatically)

4. Review SMC logs for Gx-related errors

### PCRF Rejects Sessions

**Symptom:** CCA messages contain error result codes (for example, 5xxx).

**Possible causes:**
- Session context missing required AVPs
- Origin-Realm or Destination-Realm mismatch
- PCRF policy rejects the session (for example, subscriber not found)

**Solution:**

1. Check CCA result code in SMC logs

2. Verify Origin-Realm and Destination-Realm configuration

3. Review PCRF logs for rejection reason

4. Verify subscriber exists in PCRF database

### Rules Not Activated

**Symptom:** CCA contains rule names, but rules are not applied to traffic.

**Possible causes:**
- Rule does not exist in SMC configuration
- Flow description syntax error
- Precedence conflict

**Solution:**

1. Verify rule exists under `aaa.applicationDetection.rules`:
   ```yaml
   rules:
     {RULE_NAME}:  # Must match rule name in CCA
       type: classic
       # ... configuration
   ```

2. Check SMC logs for rule activation errors

3. Review flow descriptions for syntax errors

4. Check rule precedence for conflicts (see [PCC Rules](https://docs.cennso.com/components/smc/latest/guides/aaa/policy/pcc-rules.md))

### Inline Rules Not Working

**Symptom:** Inline rule definitions in CCA are rejected or not applied.

**Possible causes:**
- Syntax error in Charging-Rule-Definition AVP
- Missing required sub-AVPs
- Invalid flow description format

**Solution:**

1. Verify all required sub-AVPs are present:
   - Charging-Rule-Name
   - Rating-Group (if charging is enabled)
   - Flow-Information or TDF-Application-Identifier
   - Metering-Method

2. Check Flow-Description syntax ([RFC 6733](https://www.rfc-editor.org/rfc/rfc6733.html) IPFilterRule)

3. Review SMC logs for parsing errors

4. Test with a simple inline rule first:
   ```yaml
   Charging-Rule-Definition:
     - Charging-Rule-Name: "test-rule"
       Rating-Group: [9999]
       Precedence: [100]
       Flow-Information:
         - Flow-Description: ["permit out ip from any to assigned"]
           Flow-Direction: [1]
       Metering-Method: [1]
       Online: [0]
       Offline: [0]
   ```

> [!TIP]
> Use static provisioning with inline rules first to verify syntax before testing with a live PCRF.
