> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/smc/3.14/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.14/config/aaa/policy/npcf.md).

# Npcf Policy Control Configuration

## Overview

Npcf_SMPolicyControl is the HTTP/2-based interface between SMC and the Policy Control Function (PCF) in 5G Core networks, defined in 3GPP TS 29.512. Through Npcf, the PCF controls PCC (Policy and Charging Control) rules for user sessions.

SMC implements the session management function role and communicates with an external PCF via the Npcf interface.

References:
- 3GPP TS 23.503 - Policy and charging control framework for the 5G System
- 3GPP TS 29.512 - 5G System; Session Management Policy Control Service
- [PCC Rules](https://docs.cennso.com/components/smc/3.14/config/aaa/policy/pcc-rules.md) - PCC rule configuration

## Critical Limitation

> [!CAUTION]
> **CRITICAL LIMITATION:** SMC's Npcf implementation supports **predefined PCC rules only**. The PCF can only reference rules by `pccRuleId` that already exist in SMC configuration. SMC cannot create or install new rules dynamically from Npcf SmPolicyDecision messages. All rules must be pre-configured in the SMC helm chart before they can be activated via Npcf.

This limitation means:
- PCF cannot define new rules with flow descriptions
- PCF cannot modify rule parameters (precedence, rating group, etc.)
- PCF can only activate, deactivate, or associate charging/traffic control decisions with existing rules

## Basic Configuration

Enable Npcf and configure the PCF endpoint:

```yaml
aaa:
  npcf:
    enabled: true
    URI: "http://pcf.5gc.example.com:8080/npcf-smpolicycontrol/v1/sm-policies"
    timeout: 5000
```

Configuration parameters:

| Parameter | Type | Description |
|---|---|---|
| enabled | boolean | Enable or disable Npcf |
| URI | string | PCF HTTP endpoint URL |
| timeout | integer | Request timeout in milliseconds |

When `enabled` is `true`, SMC sends HTTP POST requests to the PCF during session establishment, updates, and termination.

## Npcf Operations

SMC implements three Npcf operations:

### Create (POST /sm-policies)

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

**HTTP Method:** POST  
**Path:** `/sm-policies`  
**Direction:** SMC → PCF

**Body:** SmPolicyContextData containing:
- User identity (SUPI, GPSI)
- Session parameters (DNN, PDU session type, IP address)
- Network context (PLMN, location, RAT type)

**Response:** SmPolicyDecision containing:
- PCC rule references (pccRules)
- Charging decisions (chgDecs)
- Traffic control decisions (traffContDecs)

**Example request:**

```json
{
  "supi": "imsi-001010123456789",
  "dnn": "internet",
  "pduSessionId": 69,
  "pduSessionType": "IPV4",
  "ipv4Address": "10.45.0.100",
  "ratType": "EUTRA",
  "accessType": "3GPP_ACCESS",
  "servingNetwork": {
    "mcc": "001",
    "mnc": "01"
  }
}
```

**Example response:**

```json
{
  "pccRules": {
    "default-rule": {
      "pccRuleId": "default-rule",
      "refChgData": ["chg-1000"]
    }
  },
  "chgDecs": {
    "chg-1000": {
      "chgId": "chg-1000",
      "meteringMethod": "VOLUME",
      "ratingGroup": 1000,
      "online": true
    }
  }
}
```

### Update (POST /sm-policies/{smPolicyId}/update)

Sent when session parameters change.

**HTTP Method:** POST  
**Path:** `/sm-policies/{smPolicyId}/update`  
**Direction:** SMC → PCF

**Body:** SmPolicyUpdateContextData with changed parameters

**Response:** SmPolicyDecision with updated policies

**Triggers for updates:**
- Location change
- RAT type change
- Network slice change
- QoS modifications

### Delete (POST /sm-policies/{smPolicyId}/delete)

Sent when a user session terminates.

**HTTP Method:** POST  
**Path:** `/sm-policies/{smPolicyId}/delete`  
**Direction:** SMC → PCF

**Body:** SmPolicyDeleteData with termination information

**Response:** Empty (204 No Content)

## PCC Rule Activation

The PCF activates pre-configured PCC rules by sending SmPolicyDecision with `pccRules` references.

### Rule Reference Format

```json
{
  "pccRules": {
    "premium-video": {
      "pccRuleId": "premium-video",
      "refChgData": ["chg-4000"],
      "refTcData": ["tc-001"]
    }
  },
  "chgDecs": {
    "chg-4000": {
      "chgId": "chg-4000",
      "meteringMethod": "VOLUME",
      "ratingGroup": 4000,
      "online": true,
      "offline": false
    }
  },
  "traffContDecs": {
    "tc-001": {
      "tcId": "tc-001",
      "redirectInfo": {
        "redirectEnabled": true,
        "redirectAddressType": "URL",
        "redirectServerAddress": "http://portal.example.com"
      }
    }
  }
}
```

The rule "premium-video" must exist in SMC configuration:

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

**Activation process:**

1. PCF sends `pccRuleId` "premium-video" in SmPolicyDecision
2. SMC looks up "premium-video" in local configuration
3. If found, SMC activates the rule using flow descriptions from configuration
4. If not found, rule activation fails

> [!IMPORTANT]
> The `pccRuleId` in SmPolicyDecision must exactly match the rule name in SMC configuration. Names are case-sensitive.

### Charging and Traffic Control Decisions

The PCF can associate charging decisions (`chgDecs`) and traffic control decisions (`traffContDecs`) with PCC rules:

- `refChgData` - References charging decision by ID
- `refTcData` - References traffic control decision by ID

These decisions override or supplement parameters from the rule configuration.

**Example:** Rule configured for offline charging, PCF overrides to online:

```yaml
# SMC configuration
rules:
  basic-data:
    meteringMethod: 1
    offlineEnabled: true  # Configured for offline
    ratingGroup: 2000
```

```json
// PCF SmPolicyDecision
{
  "pccRules": {
    "basic-data": {
      "pccRuleId": "basic-data",
      "refChgData": ["chg-online"]
    }
  },
  "chgDecs": {
    "chg-online": {
      "chgId": "chg-online",
      "meteringMethod": "VOLUME",
      "ratingGroup": 2000,
      "online": true,    // PCF overrides to online
      "offline": false
    }
  }
}
```

## Session Context Mapping

SMC maps EPC/GTP session attributes to 5G Npcf format:

| EPC Attribute | Npcf Attribute | Notes |
|---|---|---|
| 3GPP-IMSI | supi | Format: "imsi-{IMSI}" |
| 3GPP-MSISDN | gpsi | Format: "msisdn-{MSISDN}" |
| APN | dnn | Data Network Name |
| 3GPP-PDP-Type | pduSessionType | IPV4, IPV6, IPV4V6 |
| 3GPP-NSAPI | pduSessionId | NSAPI + 64 |
| 3GPP-RAT-Type | ratType | Mapped to 5G values |
| 3GPP-User-Location-Info | userLocationInfo | Cell/tracking area |
| 3GPP-SGSN-MCC-MNC | servingNetwork | MCC/MNC |
| 3GPP-MS-TimeZone | ueTimeZone | Time zone |
| 3GPP-IMEISV | pei | Format: "imeisv-{IMEISV}" |
| Framed-IP-Address | ipv4Address | User's IPv4 address |
| Framed-IPv6-Prefix | ipv6AddressPrefix | User's IPv6 prefix |

## Unsupported Features

The following Npcf features are not supported:

- **QoS Policy** - qosDecs, qosChars
- **Usage Monitoring** - umDecs, qosMonDecs
- **Session Rules** - sessRules
- **Dynamic Rule Definition** - Cannot create rules from PCF
- **Application Detection Reporting** - No application detection feedback to PCF

## Example Configurations

### Basic Npcf with Pre-configured Rules

```yaml
aaa:
  npcf:
    enabled: true
    URI: "http://10.5.6.10:8080/npcf-smpolicycontrol/v1/sm-policies"
    timeout: 5000
  
  applicationDetection:
    rules:
      internet-basic:
        type: classic
        precedence: 1000
        meteringMethod: 1
        onlineEnabled: true
        ratingGroup: 1000
        additionalSDF:
          - "permit out ip from any to assigned"
      
      video-premium:
        type: adf
        precedence: 100
        meteringMethod: 1
        onlineEnabled: true
        ratingGroup: 3000
```

### Multiple Rules for Different Service Tiers

```yaml
aaa:
  npcf:
    enabled: true
    URI: "http://pcf.5gc.example.com:8080/npcf-smpolicycontrol/v1/sm-policies"
    timeout: 10000
  
  applicationDetection:
    rules:
      bronze-data:
        type: classic
        precedence: 300
        meteringMethod: 1
        onlineEnabled: true
        ratingGroup: 2000
        additionalSDF:
          - "permit out ip from any to assigned"
      
      silver-data:
        type: classic
        precedence: 200
        meteringMethod: 1
        onlineEnabled: true
        ratingGroup: 3000
        additionalSDF:
          - "permit out ip from any to assigned"
      
      gold-data:
        type: classic
        precedence: 100
        meteringMethod: 1
        onlineEnabled: true
        ratingGroup: 4000
        additionalSDF:
          - "permit out ip from any to assigned"
```

The PCF activates the appropriate rule based on subscriber profile.

### With Longer Timeout

```yaml
aaa:
  npcf:
    enabled: true
    URI: "http://pcf-slow.example.com:8080/npcf-smpolicycontrol/v1/sm-policies"
    timeout: 30000  # 30 seconds for slow PCF
  
  applicationDetection:
    rules:
      default-rule:
        type: classic
        precedence: 500
        meteringMethod: 1
        onlineEnabled: true
        ratingGroup: 1000
        additionalSDF:
          - "permit out ip from any to assigned"
```

## Troubleshooting

### PCF Not Reachable

**Symptom:** Sessions fail with Npcf connection errors.

**Possible causes:**
- Incorrect PCF URI
- Network connectivity issues
- PCF service not running

**Solution:**

1. Verify PCF URI is correct:
   ```yaml
   URI: "http://10.5.6.10:8080/npcf-smpolicycontrol/v1/sm-policies"
   ```

2. Test connectivity from SMC pod:
   ```bash
   kubectl exec {POD_NAME} -- curl -v {PCF_URI}
   ```

3. Check PCF service status

4. Review SMC logs for HTTP error codes

### Rule Not Found Errors

**Symptom:** PCF sends rule references but SMC reports rule not found.

**Cause:** The `pccRuleId` from PCF does not match any rule in SMC configuration.

**Solution:**

1. Verify rule exists in SMC configuration:
   ```yaml
   aaa:
     applicationDetection:
       rules:
         {RULE_NAME}:  # Must exactly match pccRuleId from PCF
           type: classic
           # ... configuration
   ```

2. Check SMC logs for the exact rule name in the error

3. Verify case-sensitivity - "Premium-Video" ≠ "premium-video"

4. Coordinate rule names between SMC configuration and PCF database

> [!TIP]
> Use lowercase names with hyphens for consistency: "premium-video", "basic-data"

### PCF Timeouts

**Symptom:** Sessions fail with timeout errors.

**Cause:** PCF takes longer than configured timeout to respond.

**Solution:**

1. Increase timeout:
   ```yaml
   npcf:
     timeout: 15000  # Increase from 5000 to 15000 milliseconds
   ```

2. Check PCF performance and load

3. Review PCF logs for slow database queries or external calls

4. Consider caching policies in PCF if possible

### Rule Activation Fails

**Symptom:** PCF sends rule reference but rule is not applied to traffic.

**Possible causes:**
- Rule exists but has invalid flow descriptions
- Rule precedence conflict
- Rule parameters conflict with session type

**Solution:**

1. Verify rule configuration syntax:
   ```yaml
   rules:
     {RULE_NAME}:
       type: classic
       additionalSDF:
         - "permit out ip from any to assigned"  # Valid syntax
   ```

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

3. Test with a simple catch-all rule first:
   ```yaml
   test-rule:
     type: classic
     precedence: 1000
     meteringMethod: 1
     onlineEnabled: false
     offlineEnabled: false
     ratingGroup: 9999
     additionalSDF:
       - "permit out ip from any to assigned"
   ```

4. Review SMC logs for rule activation errors

### Cannot Define Dynamic Rules

**Symptom:** Need to create rules dynamically from PCF but SMC rejects them.

**Cause:** This is a known limitation - SMC does not support dynamic rule creation via Npcf.

**Solution:**

Pre-configure all rules needed by the PCF in SMC:

```yaml
aaa:
  applicationDetection:
    rules:
      # Pre-configure all rules the PCF might need
      subscriber-1-rule:
        type: classic
        precedence: 100
        meteringMethod: 1
        onlineEnabled: true
        ratingGroup: 3000
        additionalSDF:
          - "permit out ip from any to assigned"
      
      subscriber-2-rule:
        type: classic
        precedence: 200
        meteringMethod: 1
        onlineEnabled: true
        ratingGroup: 3001
        additionalSDF:
          - "permit out ip from any to assigned"
```

The PCF then activates the appropriate pre-configured rule by `pccRuleId`.

> [!CAUTION]
> If you need truly dynamic rules per subscriber (for example, different flow descriptions), Npcf cannot support this. Consider using Gx instead, which supports inline rule definitions.
