| Crates.io | bss-oss-pcf |
| lib.rs | bss-oss-pcf |
| version | 0.3.0 |
| created_at | 2025-12-15 17:45:14.845917+00 |
| updated_at | 2025-12-15 17:45:14.845917+00 |
| description | Policy Control Function (PCF/PCRF) for 3G/4G/5G/6G networks - Policy Control, Charging Rules, and Quota Management with Diameter protocol support |
| homepage | |
| repository | https://github.com/rabbittrix/BSS-OSS-Rust-Ecosystem.git |
| max_upload_size | |
| id | 1986449 |
| size | 179,630 |
A high-performance Policy Control Function (PCF), formerly known as PCRF (Policy and Charging Rules Function), for 3G, 4G, 5G, and 6G mobile telecommunications networks.
The PCF is the "brain" of policies in mobile telecommunications networks. It makes real-time decisions about:
use bss_oss_pcf::{PcfEngine, PolicyRequest, NetworkGeneration};
use chrono::Utc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create PCF engine
let pcf = PcfEngine::new();
// Create policy request
let request = PolicyRequest {
subscriber_id: "1234567890".to_string(),
imsi: "123456789012345".to_string(),
network_generation: NetworkGeneration::FiveG,
apn: "internet".to_string(),
service_type: "video_streaming".to_string(),
application_id: Some("youtube.com".to_string()),
location: None,
time_of_day: Some(Utc::now()),
};
// Evaluate policy
let decision = pcf.evaluate_policy(&request).await?;
println!("Access granted: {}", decision.access_granted);
println!("QoS Priority: {}", decision.qos.priority);
println!("Max Download: {} Kbps", decision.qos.max_download_bandwidth_kbps);
println!("Zero-rated: {}", decision.charging_rules.iter().any(|r| r.zero_rating));
Ok(())
}
use bss_oss_pcf::{PcfEngine, SubscriberProfile, NetworkGeneration, Quota};
use chrono::Utc;
let pcf = PcfEngine::new();
let profile = SubscriberProfile {
subscriber_id: "1234567890".to_string(),
imsi: "123456789012345".to_string(),
plan_name: "Premium Unlimited".to_string(),
plan_type: "postpaid".to_string(),
quota: Quota {
total_quota_bytes: 100_000_000_000, // 100 GB
used_quota_bytes: 0,
remaining_quota_bytes: 100_000_000_000,
notification_threshold_percent: 80,
exceeded: false,
throttled_bandwidth_kbps: None,
last_update: Utc::now(),
},
active_policies: vec!["premium_qos".to_string()],
zero_rated_services: vec!["whatsapp.com".to_string()],
supported_networks: vec![NetworkGeneration::FourG, NetworkGeneration::FiveG],
last_update: Utc::now(),
};
pcf.register_subscriber(profile);
// Update quota after data usage
pcf.update_quota_usage("1234567890", 1_000_000_000).await?; // 1 GB used
// Get updated quota
let profile = pcf.get_subscriber_profile("1234567890").await?;
println!("Quota used: {}%", profile.quota.usage_percent());
use bss_oss_pcf::diameter::{DiameterHandler, GxMessage, GxRequestType};
let mut handler = DiameterHandler::new();
handler.set_pcf_engine(Arc::new(pcf));
let gx_request = GxMessage {
session_id: "session-123".to_string(),
subscriber_id: "1234567890".to_string(),
apn: "internet".to_string(),
request_type: GxRequestType::Initial,
policy_decision: None,
};
let response = handler.handle_gx_request(&gx_request).await?;
┌─────────────────────────────────────────────────────────┐
│ PCF Engine │
├─────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Policy │ │ Charging │ │ Quota │ │
│ │ Control │ │ Rules │ │ Management │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Diameter │ │ AI │ │ Subscriber │ │
│ │ Protocol │ │ Integration │ │ Profiles │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
└─────────────────────────────────────────────────────────┘
│ │ │
▼ ▼ ▼
┌────────┐ ┌────────┐ ┌────────┐
│ P-GW │ │ OCS │ │ CGF │
│ (Gx) │ │ (Gy) │ │ (Gz) │
└────────┘ └────────┘ └────────┘
The PCF supports different QoS profiles for various service types:
Zero-rating allows certain services to not count against data quotas:
use bss_oss_pcf::models::ZeroRatingRule;
use uuid::Uuid;
let rule = ZeroRatingRule {
rule_id: Uuid::new_v4(),
service_identifier: "whatsapp.com".to_string(),
plan_name: None, // Applies to all plans
active: true,
};
pcf.charging_rules.add_zero_rating_rule(rule);
The PCF provides hooks for AI/ML integration:
See the ai module for more details.
MIT License - see LICENSE file for details.
Contributions are welcome! Please see the main project CONTRIBUTING.md for guidelines.
bss-oss-policy-engine: General policy engine for BSS/OSSrevenue-management: Charging and billing integrationbss-oss-event-bus: Event-driven architecture support