> 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/pcc-rules.md).

# PCC Rules Configuration

## Overview

Policy and Charging Control (PCC) rules define how traffic flows are identified, controlled, and measured. Rules combine:
- **Flow identification** - Which packets the rule applies to
- **QoS parameters** - Quality of Service requirements
- **Charging parameters** - How usage is measured and charged
- **Traffic control** - Redirection, steering, or blocking

SMC uses PCC rules defined in the Gx AVP (Attribute-Value Pair) format from 3GPP TS 29.212. Rules are pre-configured in the SMC helm chart and can be referenced by both Diameter Gx and Npcf interfaces.

References:
- 3GPP TS 23.203 - Policy and charging control architecture
- 3GPP TS 29.212 - Gx reference point
- 3GPP TS 29.512 - Npcf_SMPolicyControl Service

## Rule Configuration

Rules are defined under `aaa.applicationDetection.rules` in the helm chart:

```yaml
aaa:
  applicationDetection:
    rules:
      premium-video:
        type: classic
        precedence: 50
        meteringMethod: 1
        onlineEnabled: true
        ratingGroup: 4000
        additionalSDF:
          - "permit out ip from any to assigned"
```

Each rule is identified by a unique name (for example, `premium-video`) that can be referenced by policy interfaces.

## Rule Types

SMC supports two types of traffic identification:

### Classic Rules (Flow-Based)

Classic rules use IP filter descriptions to match traffic flows. The flow descriptions follow [RFC 6733](https://www.rfc-editor.org/rfc/rfc6733.html) IPFilterRule format and are mapped to PFCP SDF_Filter.

```yaml
rules:
  web-traffic:
    type: classic
    precedence: 100
    additionalSDF:
      - "permit out tcp from any to assigned 80"
      - "permit out tcp from any to assigned 443"
    meteringMethod: 1
    onlineEnabled: true
    ratingGroup: 1000
```

Flow descriptions specify:
- **Action** - `permit` or `deny`
- **Direction** - `in` or `out`
- **Protocol** - `tcp`, `udp`, `icmp`, `ip`, or protocol number
- **Source** - IP address or `any`
- **Destination** - IP address or `assigned` (user's IP)
- **Ports** - Specific ports or port ranges (for TCP/UDP)

Common flow description patterns:

```yaml
# All traffic
additionalSDF:
  - "permit out ip from any to assigned"

# HTTP and HTTPS
additionalSDF:
  - "permit out tcp from any to assigned 80"
  - "permit out tcp from any to assigned 443"

# Specific server
additionalSDF:
  - "permit out tcp from 10.1.2.3 to assigned 5000"

# Port range
additionalSDF:
  - "permit out udp from any to assigned 10000-20000"

# Bidirectional (requires two rules)
additionalSDF:
  - "permit out ip from any to assigned"
  - "permit in ip from assigned to any"
```

> [!NOTE]
> Each flow description is mapped to both UPLINK and DOWNLINK directions in PFCP by default.

### Application Detection Rules (ADF)

Application detection rules use the TDF-Application-Identifier AVP. The rule name becomes the application identifier that the UPF (User Plane Function) or TDF (Traffic Detection Function) must recognise.

```yaml
rules:
  facebook:
    type: adf
    precedence: 200
    meteringMethod: 1
    onlineEnabled: true
    ratingGroup: 2000
```

The rule name "facebook" is sent as the TDF-Application-Identifier. The UPF must be configured to detect Facebook traffic and associate it with this identifier.

> [!IMPORTANT]
> Application detection rules require UPF support for deep packet inspection (DPI) or application recognition.

## Rule Parameters

### precedence

The order in which rules are evaluated when multiple rules match the same traffic. Lower values have higher priority.

```yaml
rules:
  high-priority:
    precedence: 10  # Evaluated first
  low-priority:
    precedence: 100  # Evaluated later
```

**Type:** Unsigned32  
**Range:** 0 to 4294967295  
**Recommendation:** Use multiples of 10 to allow inserting rules between existing ones

### meteringMethod

Defines what is measured for charging purposes.

```yaml
rules:
  volume-based:
    meteringMethod: 1  # VOLUME
```

| Value | Method | Description |
|---|---|---|
| 0 | DURATION | Measure session time only |
| 1 | VOLUME | Measure data volume (bytes) |
| 2 | DURATION_VOLUME | Measure both time and volume |
| 3 | EVENT | Measure discrete events |

**Most common:** `1` (VOLUME) for mobile data services

### ratingGroup

Identifies the charging category for the traffic. Multiple rules can share the same rating group to aggregate usage.

```yaml
rules:
  video-720p:
    ratingGroup: 3000
  video-1080p:
    ratingGroup: 3000  # Same rating group as 720p
```

**Type:** Unsigned32  
**Reference:** [RFC 4006](https://www.rfc-editor.org/rfc/rfc4006.html), section 5.1.2

### onlineEnabled

Enable online charging (immediate billing through Diameter Ro).

```yaml
rules:
  prepaid-service:
    onlineEnabled: true
    ratingGroup: 5000
```

**Values:**
- `true` or `1` - Online charging enabled
- `false` or `0` - Online charging disabled

When enabled, SMC sends Credit-Control-Request messages to the OCS (Online Charging System) before allowing traffic.

### offlineEnabled

Enable offline charging (delayed billing through Diameter Rf or RADIUS accounting).

```yaml
rules:
  postpaid-service:
    offlineEnabled: true
    ratingGroup: 6000
```

**Values:**
- `true` or `1` - Offline charging enabled
- `false` or `0` - Offline charging disabled

When enabled, SMC generates accounting records (CDRs) that are sent to the charging system.

### onlineRatingGroup

Override the `ratingGroup` for online charging specifically.

```yaml
rules:
  mixed-charging:
    ratingGroup: 7000
    onlineRatingGroup: 7001   # Different rating group for online
    offlineRatingGroup: 7002  # Different rating group for offline
    onlineEnabled: true
    offlineEnabled: true
```

**Use case:** When online and offline charging need to be reported with different rating groups.

### offlineRatingGroup

Override the `ratingGroup` for offline charging specifically.

### permittedIPs

Automatically generate flow descriptions for specific IPv4 addresses. This creates rules matching traffic from those addresses to the user's assigned IP.

```yaml
rules:
  partner-servers:
    type: classic
    precedence: 150
    permittedIPs:
      - "10.1.2.3"
      - "10.1.2.4"
    meteringMethod: 1
    ratingGroup: 8000
```

This is equivalent to:

```yaml
additionalSDF:
  - "permit out ip from 10.1.2.3 to assigned"
  - "permit out ip from 10.1.2.4 to assigned"
```

## Rule Bases

A rule base is a named collection of rules that can be activated together. Configure the rule base name:

```yaml
aaa:
  applicationDetection:
    rulesBaseName: "default-rules"
    rules:
      rule-1:
        type: classic
        precedence: 100
        # ... configuration
      rule-2:
        type: classic
        precedence: 200
        # ... configuration
```

The rule base "default-rules" contains both "rule-1" and "rule-2". Policy interfaces can activate the entire base with a single reference.

**Use case:** Group related rules for common activation (for example, all rules for a specific service tier).

## QoS enforcement

QoS enforcement applies bandwidth limits to individual charging rules at the UPF. Two types of limit are supported:

- **Maximum Bit Rate (MBR)** — caps the peak bit rate for the matched traffic.
- **Guaranteed Bit Rate (GBR)** — reserves a minimum bit rate for the matched traffic.

When a charging rule includes a `qosInformation` map, SMC converts the bandwidth AVPs into a PFCP Quality Enforcement Rule (QER) and links it to all Packet Detection Rules (PDRs) for that charging rule. This allows the UPF to enforce per-rule MBR and GBR limits.

### Supported AVPs

The following table lists the supported AVPs and their conversion to PFCP fields:

| Helm field | AVP | Unit | PFCP field |
|---|---|---|---|
| `Max-Requested-Bandwidth-UL` | Max-Requested-Bandwidth-UL | bit/s | MBR UL (kbit/s) |
| `Max-Requested-Bandwidth-DL` | Max-Requested-Bandwidth-DL | bit/s | MBR DL (kbit/s) |
| `Extended-Max-Requested-BW-UL` | Extended-Max-Requested-BW-UL | kbit/s | MBR UL (kbit/s) |
| `Extended-Max-Requested-BW-DL` | Extended-Max-Requested-BW-DL | kbit/s | MBR DL (kbit/s) |
| `Guaranteed-Bitrate-UL` | Guaranteed-Bitrate-UL | bit/s | GBR UL (kbit/s) |
| `Guaranteed-Bitrate-DL` | Guaranteed-Bitrate-DL | bit/s | GBR DL (kbit/s) |
| `Extended-GBR-UL` | Extended-GBR-UL | kbit/s | GBR UL (kbit/s) |
| `Extended-GBR-DL` | Extended-GBR-DL | kbit/s | GBR DL (kbit/s) |

When both extended and non-extended AVPs for the same direction are present, the `Extended-*` value takes precedence.

The gate status is always OPEN — the QER enforces rate limits but does not block traffic.

> [!CAUTION]
> **Always supply both UL and DL AVPs together.** The PFCP MBR IE (3GPP TS 29.244) encodes uplink and downlink maximum bitrates as two fixed 5-octet fields in a single IE. There is no mechanism to omit one direction.
>
> 3GPP TS 29.212 (sections 4b.5.1.3 and 4b.5.12) consistently pairs the two AVPs: "Only the `Max-Requested-Bandwidth-UL` AVP **and** the `Max-Requested-Bandwidth-DL` AVP ... shall be used." The Diameter ABNF grammar marks both as individually optional, but the specification prose makes clear they are expected as a pair. Sending only one direction violates the specification in a way the grammar cannot catch.
>
> When a direction AVP is absent, SMC substitutes 0 kbit/s to satisfy the mandatory dual-field PFCP IE. Zero kbit/s is not a neutral or unlimited value in the PFCP specification. Most UPF implementations treat it as an instruction to suppress all traffic in that direction, causing asymmetric traffic loss.

The following limitations apply to QoS enforcement:

- **MBR requires UPF support** — the UPF must support PFCP QER enforcement. UPG gained support for MBR enforcement in a recent release; check the UPG release notes for the minimum required version.
- **GBR requires UPF support** — the UPF must support PFCP GBR enforcement. UPG does not currently support GBR enforcement; do not configure GBR AVPs when using UPG.
- **No GTP negotiation** — SMC uses QoS values as-is and does not feed them back into GTP Create/Update Bearer responses. The UE does not receive QoS parameters from SMC in GTP signalling.
- **Extended AVPs** — you can use `Extended-*` AVPs without the corresponding non-extended counterpart.

### Configuration

The following example configures a rule with MBR limits. SMC enforces the maximum bit rates in both uplink and downlink directions at the UPF:

```yaml
aaa:
  applicationDetection:
    rules:
      premium-video:
        type: classic
        precedence: 50
        meteringMethod: 1
        onlineEnabled: true
        ratingGroup: 3000
        additionalSDF:
          - "permit out ip from any to assigned"
        qosInformation:
          - Max-Requested-Bandwidth-UL: 10000000   # 10 Mbit/s (bit/s)
            Max-Requested-Bandwidth-DL: 20000000   # 20 Mbit/s (bit/s)
```

To also guarantee a minimum bit rate, add GBR AVPs alongside the MBR AVPs:

```yaml
        qosInformation:
          - Max-Requested-Bandwidth-UL: 10000000   # 10 Mbit/s (bit/s)
            Max-Requested-Bandwidth-DL: 20000000   # 20 Mbit/s (bit/s)
            Guaranteed-Bitrate-UL: 2000000         #  2 Mbit/s (bit/s)
            Guaranteed-Bitrate-DL: 4000000         #  4 Mbit/s (bit/s)
```

For rates above 4 Gbit/s, or when interoperating with systems that prefer kbit/s units, use the extended AVPs:

```yaml
        qosInformation:
          - Extended-Max-Requested-BW-UL: 10000   # 10 Mbit/s (kbit/s)
            Extended-Max-Requested-BW-DL: 20000   # 20 Mbit/s (kbit/s)
```

## Redirect Information

Rules can include traffic redirection to a captive portal or content server.

```yaml
rules:
  captive-portal:
    type: classic
    precedence: 50
    additionalSDF:
      - "permit out tcp from any to assigned 80"
      - "permit out tcp from any to assigned 443"
    meteringMethod: 3  # EVENT
    Redirect-Information:
      Redirect-Server-Address: "http://portal.example.com/landing"
      Redirect-Address-Type: 0  # IPv4
```

> [!NOTE]
> Redirect-Information configuration details are pending documentation (marked TBD in current documentation).

## Example Configurations

### Basic Data Service

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

This rule:
- Matches all IP traffic
- Measures data volume
- Uses offline charging only
- Has low priority (1000)

### Prepaid Video Service

```yaml
aaa:
  applicationDetection:
    rules:
      prepaid-video:
        type: adf
        precedence: 50
        meteringMethod: 1
        onlineEnabled: true
        offlineEnabled: false
        ratingGroup: 3000
```

This rule:
- Uses application detection (UPF identifies video traffic)
- Has high priority (50)
- Uses online charging (prepaid)
- No offline charging

### Premium Service with Separate Rating Groups

```yaml
aaa:
  applicationDetection:
    rules:
      premium-service:
        type: classic
        precedence: 100
        meteringMethod: 2  # DURATION_VOLUME
        onlineEnabled: true
        offlineEnabled: true
        ratingGroup: 5000
        onlineRatingGroup: 5001
        offlineRatingGroup: 5002
        additionalSDF:
          - "permit out ip from any to assigned"
```

This rule:
- Measures both duration and volume
- Uses both online and offline charging
- Separate rating groups for each charging type

### Zero-Rated Service (Partner Traffic)

```yaml
aaa:
  applicationDetection:
    rules:
      partner-content:
        type: classic
        precedence: 10  # Very high priority
        meteringMethod: 1
        onlineEnabled: false
        offlineEnabled: false  # No charging
        ratingGroup: 9999
        permittedIPs:
          - "203.0.113.10"
          - "203.0.113.20"
```

This rule:
- Has very high priority (10)
- No charging (zero-rated)
- Only applies to traffic from specific partner servers

### Multiple Services Rule Base

```yaml
aaa:
  applicationDetection:
    rulesBaseName: "bronze-tier"
    rules:
      bronze-web:
        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"
      
      bronze-general:
        type: classic
        precedence: 200
        meteringMethod: 1
        onlineEnabled: true
        ratingGroup: 2001
        additionalSDF:
          - "permit out ip from any to assigned"
```

The rule base "bronze-tier" activates both rules together for bronze-level subscribers.

## Rule Activation

Rules are activated through policy interfaces:

- **Diameter Gx** - PCRF sends Charging-Rule-Install AVP with rule names
- **Npcf** - PCF sends SmPolicyDecision with pccRuleId references

For detailed activation procedures, see:
- [Gx Policy Control](https://docs.cennso.com/components/smc/latest/guides/aaa/policy/gx.md)
- [Npcf Policy Control](https://docs.cennso.com/components/smc/latest/guides/aaa/policy/npcf.md)

## Troubleshooting

### Rule Not Matched

**Symptom:** Traffic does not match the expected rule.

**Possible causes:**
- Flow description syntax error
- Precedence conflict (higher-priority rule matched first)
- Rule not activated by policy interface

**Solution:**

1. Verify flow description syntax ([RFC 6733](https://www.rfc-editor.org/rfc/rfc6733.html) IPFilterRule format)

2. Check rule precedence - lower values are evaluated first:
   ```yaml
   precedence: 50  # This rule is evaluated before precedence: 100
   ```

3. Verify rule is activated by checking PFCP sessions

4. Test with a very general rule:
   ```yaml
   additionalSDF:
     - "permit out ip from any to assigned"
   ```

### Application Detection Not Working

**Symptom:** ADF-type rules do not match traffic.

**Cause:** UPF does not support application detection or does not recognise the application identifier.

**Solution:**

1. Verify UPF supports DPI/application detection

2. Check UPF configuration for application identifier mapping

3. Use classic flow-based rules as a fallback:
   ```yaml
   type: classic  # Instead of adf
   additionalSDF:
     - "permit out tcp from any to assigned 443"
   ```

### Charging Not Working

**Symptom:** Traffic matches rule but charging records are not generated.

**Possible causes:**
- `onlineEnabled` and `offlineEnabled` both `false`
- `ratingGroup` not configured
- Charging interface (Rf/Ro/RADIUS) not enabled

**Solution:**

1. Enable at least one charging method:
   ```yaml
   onlineEnabled: true
   # or
   offlineEnabled: true
   ```

2. Configure rating group:
   ```yaml
   ratingGroup: 3000
   ```

3. Verify charging interfaces are enabled (see [Charging Configuration](https://docs.cennso.com/components/smc/latest/guides/aaa/charging/overview.md))

### Precedence Conflicts

**Symptom:** Lower-priority rule is never matched.

**Cause:** Higher-priority rule with broader flow description matches all traffic first.

**Solution:**

1. Reorder precedence values - more specific rules should have lower precedence values (higher priority):
   ```yaml
   rules:
     specific-service:
       precedence: 50   # High priority
       additionalSDF:
         - "permit out tcp from any to assigned 443"
     
     general-traffic:
       precedence: 200  # Low priority
       additionalSDF:
         - "permit out ip from any to assigned"
   ```

2. Use more specific flow descriptions for higher-priority rules

3. Review all active rules to identify conflicts
