Skip to content

Diameter Gx Interface

Overview

The Diameter Gx interface is used for policy and charging control between the Policy and Charging Enforcement Function (PCEF) and the Policy and Charging Rules Function (PCRF). It enables dynamic policy control, QoS management, and charging rule provisioning.

Interface Specifications

Gx Interface (3GPP TS 29.212)

  • Application ID: 16777238
  • Vendor ID: 10415 (3GPP)
  • Commands:
  • Credit-Control-Request (CCR)
  • Credit-Control-Answer (CCA)
  • Re-Auth-Request (RAR)
  • Re-Auth-Answer (RAA)
  • Event Triggers:
  • SGSN_CHANGE
  • QOS_CHANGE
  • RAT_CHANGE
  • TFT_CHANGE
  • PLMN_CHANGE
  • LOSS_OF_BEARER
  • RECOVERY_OF_BEARER
  • IP_CAN_CHANGE

Message Flows

Basic Policy Control Flow

sequenceDiagram
    participant PCEF as Policy Enforcement
    participant PCRF as Policy Control

    PCEF->>PCRF: CCR-Initial
    PCRF->>PCEF: CCA-Initial (PCC Rules)
    Note over PCEF,PCRF: Policy Enforcement
    PCRF->>PCEF: RAR (Policy Update)
    PCEF->>PCRF: RAA (Update Response)
    Note over PCEF,PCRF: Rule Modification
    PCEF->>PCRF: CCR-Update
    PCRF->>PCEF: CCA-Update

Implementation Examples

Session Establishment

from telcoapi.diameter import gx

# Initialize Gx client
client = gx.GxClient(
    host="pcef.example.com",
    realm="example.com",
    destination_host="pcrf.example.com",
    destination_realm="example.com"
)

# Send initial request
ccr_i = client.create_ccr(
    session_id="session123",
    cc_request_type="INITIAL",
    subscription_id="123456789",
    network_request_support="SUPPORTED",
    ip_can_type="3GPP-EPS",
    rat_type="EUTRAN",
    default_qos={
        "qci": 9,
        "arp": {
            "priority_level": 8,
            "pre_emption_capability": "NOT_PRE_EMPTIBLE",
            "pre_emption_vulnerability": "PRE_EMPTIBLE"
        }
    }
)

response = client.send_ccr(ccr_i)
print(f"Initial policy response: {response}")

Policy Update Handling

# Handle Re-Auth-Request
@client.on_rar
def handle_rar(rar):
    # Process policy updates
    for rule in rar.charging_rules:
        install_charging_rule(rule)

    # Send Re-Auth-Answer
    raa = client.create_raa(
        session_id=rar.session_id,
        result_code=2001  # DIAMETER_SUCCESS
    )
    client.send_raa(raa)

Usage Monitoring

# Send usage report
ccr_u = client.create_ccr(
    session_id="session123",
    cc_request_type="UPDATE",
    usage_monitoring_report=[{
        "monitoring_key": "key1",
        "used_service_unit": {
            "total_octets": 1000000,
            "input_octets": 500000,
            "output_octets": 500000
        }
    }],
    event_trigger=["USAGE_REPORT"]
)

response = client.send_ccr(ccr_u)

Vendor Integration

Nokia PCRF Integration

# Nokia PCRF configuration
client.set_vendor_config({
    "vendor_id": 28458,  # Nokia vendor ID
    "product_name": "Nokia PCRF",
    "firmware_revision": 1,
    "custom_avps": [
        {"code": 8001, "name": "Nokia-QoS-Profile"},
        {"code": 8002, "name": "Nokia-Charging-Rule"}
    ]
})

Ericsson PCRF Integration

# Ericsson configuration
client.set_vendor_config({
    "vendor_id": 193,    # Ericsson vendor ID
    "product_name": "Ericsson PCRF",
    "firmware_revision": 1,
    "custom_avps": [
        {"code": 9001, "name": "Ericsson-Policy-Rule"},
        {"code": 9002, "name": "Ericsson-Usage-Monitoring"}
    ]
})

Error Handling

Common Error Scenarios

Result Code Name Description Action
5030 DIAMETER_ERROR_INITIAL_PARAMETERS Invalid parameters Check configuration
5031 DIAMETER_ERROR_TRIGGER_EVENT Invalid trigger Verify event trigger
5032 DIAMETER_PCC_RULE_EVENT Rule installation failed Check rule parameters
5033 DIAMETER_ERROR_BEARER_NOT_AUTHORIZED Unauthorized bearer Check QoS parameters

Error Handling Example

from telcoapi.diameter.exceptions import GxError

try:
    response = client.send_ccr(ccr_request)
except GxError as e:
    if e.result_code == 5032:  # PCC_RULE_EVENT
        # Handle rule installation failure
        handle_rule_failure(e.failed_rules)
    else:
        # Log error and take appropriate action
        logger.error(f"Gx interface error: {e}")

Monitoring

Key Metrics

  1. Rule Installation Success Rate
  2. Policy Update Success Rate
  3. Average Response Time
  4. Active Sessions Count
  5. Usage Monitoring Accuracy

Monitoring Example

# Register monitoring callbacks
@client.on_metrics
def collect_gx_metrics(metrics):
    print(f"Rule installation success rate: {metrics.rule_success_rate}%")
    print(f"Average response time: {metrics.avg_response_time}ms")
    print(f"Active sessions: {metrics.active_sessions}")

Configuration Examples

Basic Configuration

gx_interface:
  host: "pcef.example.com"
  realm: "example.com"
  port: 3868
  application_id: 16777238
  vendor_id: 10415
  security:
    tls_enabled: true
    certificate: "/path/to/cert.pem"
    private_key: "/path/to/key.pem"
  peers:
    - host: "pcrf1.example.com"
      realm: "example.com"
      port: 3868
      role: "server"
    - host: "pcrf2.example.com"
      realm: "example.com"
      port: 3868
      role: "server"

Advanced Configuration

gx_interface:
  host: "pcef.example.com"
  realm: "example.com"
  port: 3868
  application_id: 16777238
  vendor_id: 10415
  vendor_specific:
    vendor_id: 28458
    product_name: "Example PCEF Client"
    firmware_revision: 1
  security:
    tls_enabled: true
    certificate: "/path/to/cert.pem"
    private_key: "/path/to/key.pem"
    cipher_suites:
      - "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
      - "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
  routing:
    strategy: "round_robin"
    failover_enabled: true
    retry_count: 3
    timeout: 5000
  policy_management:
    max_rules_per_session: 256
    rule_cleanup_interval: 300
    usage_report_threshold: 80
  peers:
    - host: "pcrf1.example.com"
      realm: "example.com"
      port: 3868
      role: "server"
      weight: 100
    - host: "pcrf2.example.com"
      realm: "example.com"
      port: 3868
      role: "server"
      weight: 100

Best Practices

  1. Implement proper rule management
  2. Handle policy updates efficiently
  3. Use secure transport (TLS)
  4. Implement proper failover
  5. Monitor rule installation
  6. Handle usage monitoring
  7. Implement QoS enforcement
  8. Use appropriate timeouts
  9. Handle multiple bearers
  10. Implement proper event handling