Diameter Rf Interface¶
Overview¶
The Diameter Rf interface is used for offline charging in IP Multimedia Subsystem (IMS) networks. It supports the transfer of charging information between network elements and the Charging Data Function (CDF).
Interface Specifications¶
Rf Interface (3GPP TS 32.299)¶
- Application ID: 3 (Accounting)
- Vendor ID: 10415 (3GPP)
- Commands:
- Accounting-Request (ACR)
- Accounting-Answer (ACA)
- Record Types:
- START
- INTERIM
- STOP
- EVENT
Message Flows¶
Basic Accounting Flow¶
sequenceDiagram
participant CTF as Charging Trigger Function
participant CDF as Charging Data Function
CTF->>CDF: ACR[Start]
CDF->>CTF: ACA[Start]
Note over CTF,CDF: Service Delivery
CTF->>CDF: ACR[Interim]
CDF->>CTF: ACA[Interim]
Note over CTF,CDF: Service Continues
CTF->>CDF: ACR[Stop]
CDF->>CTF: ACA[Stop]
Implementation Examples¶
Session Start Record¶
from telcoapi.diameter import rf
# Initialize Rf client
client = rf.RfClient(
host="client.example.com",
realm="example.com",
destination_host="cdf.example.com",
destination_realm="example.com"
)
# Send start record
acr_start = client.create_acr(
session_id="session123",
accounting_record_type="START",
subscription_id="123456789",
service_information={
"ims_information": {
"node_functionality": "S-CSCF",
"role_of_node": ["ORIGINATING"]
}
}
)
response = client.send_acr(acr_start)
print(f"Start record response: {response}")
Interim Record¶
# Send interim record
acr_interim = client.create_acr(
session_id="session123",
accounting_record_type="INTERIM",
subscription_id="123456789",
service_information={
"ims_information": {
"node_functionality": "S-CSCF",
"role_of_node": ["ORIGINATING"],
"inter_operator_identifier": [{
"originating_ioi": "operator-a.com",
"terminating_ioi": "operator-b.com"
}]
}
}
)
response = client.send_acr(acr_interim)
Stop Record¶
# Send stop record
acr_stop = client.create_acr(
session_id="session123",
accounting_record_type="STOP",
subscription_id="123456789",
service_information={
"ims_information": {
"node_functionality": "S-CSCF",
"role_of_node": ["ORIGINATING"],
"cause_code": 200,
"session_priority": "NORMAL"
},
"time_stamps": {
"sip_request_timestamp": "2024-02-20T10:00:00Z",
"sip_response_timestamp": "2024-02-20T10:01:30Z"
}
}
)
response = client.send_acr(acr_stop)
Vendor Integration¶
Huawei CDF Integration¶
# Huawei CDF configuration
client.set_vendor_config({
"vendor_id": 2011, # Huawei vendor ID
"product_name": "Huawei CDF",
"firmware_revision": 1,
"custom_avps": [
{"code": 7001, "name": "Huawei-Charging-Node"},
{"code": 7002, "name": "Huawei-Session-Priority"}
]
})
Oracle CDF Integration¶
# Oracle configuration
client.set_vendor_config({
"vendor_id": 111, # Oracle vendor ID
"product_name": "Oracle CDF",
"firmware_revision": 1,
"custom_avps": [
{"code": 6001, "name": "Oracle-Service-Context"},
{"code": 6002, "name": "Oracle-Record-Priority"}
]
})
Error Handling¶
Common Error Scenarios¶
Result Code | Name | Description | Action |
---|---|---|---|
5001 | USER_UNKNOWN | Unknown user | Verify user identity |
5002 | DIAMETER_UNABLE_TO_DELIVER | Delivery failed | Check connectivity |
5003 | DIAMETER_TOO_BUSY | System overloaded | Implement backoff |
5004 | DIAMETER_LOOP_DETECTED | Routing loop | Check configuration |
Error Handling Example¶
from telcoapi.diameter.exceptions import AccountingError
try:
response = client.send_acr(acr_request)
except AccountingError as e:
if e.result_code == 5003: # TOO_BUSY
# Implement exponential backoff
retry_with_backoff(e.request)
else:
# Log error and take appropriate action
logger.error(f"Accounting error: {e}")
Monitoring¶
Key Metrics¶
- Record Delivery Success Rate
- Average Response Time
- Record Generation Rate
- File Creation Time
- CDR Processing Rate
Monitoring Example¶
# Register monitoring callbacks
@client.on_metrics
def collect_accounting_metrics(metrics):
print(f"Record delivery success rate: {metrics.success_rate}%")
print(f"Average response time: {metrics.avg_response_time}ms")
print(f"Records per second: {metrics.records_per_second}")
Configuration Examples¶
Basic Configuration¶
rf_interface:
host: "client.example.com"
realm: "example.com"
port: 3868
application_id: 3
vendor_id: 10415
security:
tls_enabled: true
certificate: "/path/to/cert.pem"
private_key: "/path/to/key.pem"
peers:
- host: "cdf1.example.com"
realm: "example.com"
port: 3868
role: "server"
- host: "cdf2.example.com"
realm: "example.com"
port: 3868
role: "server"
Advanced Configuration¶
rf_interface:
host: "client.example.com"
realm: "example.com"
port: 3868
application_id: 3
vendor_id: 10415
vendor_specific:
vendor_id: 2011
product_name: "Example CDF 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
record_management:
interim_interval: 300
file_format: "ASN.1"
file_rotation: 3600
compression_enabled: true
peers:
- host: "cdf1.example.com"
realm: "example.com"
port: 3868
role: "server"
weight: 100
- host: "cdf2.example.com"
realm: "example.com"
port: 3868
role: "server"
weight: 100
Best Practices¶
- Implement reliable record delivery
- Use appropriate interim intervals
- Enable TLS for security
- Implement proper failover
- Monitor record delivery rates
- Handle file rotation properly
- Implement record correlation
- Use appropriate timestamps
- Handle multi-session scenarios
- Implement proper CDR verification