Crates.io | rs-pfcp |
lib.rs | rs-pfcp |
version | 0.1.0 |
created_at | 2025-09-25 18:38:11.748107+00 |
updated_at | 2025-09-25 18:38:11.748107+00 |
description | High-performance Rust implementation of PFCP (Packet Forwarding Control Protocol) for 5G networks with 100% 3GPP TS 29.244 Release 18 compliance |
homepage | https://github.com/xandlom/rs-pfcp |
repository | https://github.com/xandlom/rs-pfcp |
max_upload_size | |
id | 1854970 |
size | 10,849,876 |
A high-performance Rust implementation of the PFCP (Packet Forwarding Control Protocol) for 5G networks, providing 100% compliance with 3GPP TS 29.244 Release 18 specification.
PFCP is the critical communication protocol between Control Plane and User Plane functions in 5G networks:
Add to your Cargo.toml
:
[dependencies]
rs-pfcp = "0.1.0"
use rs_pfcp::message::{SessionEstablishmentRequest, SessionEstablishmentRequestBuilder};
use rs_pfcp::ie::{NodeId, Cause, CauseValue};
// Create a session establishment request
let request = SessionEstablishmentRequestBuilder::new(session_id, sequence_number)
.node_id(NodeId::from_ipv4("10.0.0.1".parse()?))
.fseid(fseid_ie)
.create_pdrs(vec![create_pdr_ie])
.create_fars(vec![create_far_ie])
.build()?;
// Serialize to bytes for network transmission
let bytes = request.marshal();
// Parse received messages
let parsed_msg = rs_pfcp::message::parse(&bytes)?;
match parsed_msg.msg_type() {
MsgType::SessionEstablishmentRequest => {
// Handle session establishment
println!("Received session establishment for SEID: {:016x}",
parsed_msg.seid().unwrap_or(0));
}
_ => {} // Handle other message types
}
The library includes comprehensive examples for real-world scenarios:
# Run PFCP heartbeat server
cargo run --example heartbeat-server -- --interface lo --port 8805
# Run session client connecting to UPF
cargo run --example session-client -- --address 127.0.0.1 --sessions 5
# Analyze captured PFCP traffic
cargo run --example pcap-reader -- --pcap traffic.pcap --format yaml
# Demo quota exhaustion reporting
cd examples && ./test_session_report.sh lo
rs-pfcp/
โโโ src/ie/ # Information Elements (69 types)
โ โโโ f_teid.rs # F-TEID with 3GPP compliant CHOOSE flags
โ โโโ pdn_type.rs # PDN connection types (IPv4/IPv6/Non-IP)
โ โโโ snssai.rs # 5G Network Slicing identifiers
โ โโโ ...
โโโ src/message/ # PFCP Messages (18 types)
โ โโโ session_*.rs # Session lifecycle management
โ โโโ association_*.rs # Node association handling
โ โโโ heartbeat.rs # Keep-alive mechanism
โโโ examples/ # Production-ready examples
โโโ session-server/ # UPF simulator
โโโ session-client/ # SMF simulator
โโโ pcap-reader/ # Traffic analysis tool
Document | Purpose |
---|---|
IE_SUPPORT.md | Complete Information Element implementation status |
PFCP_MESSAGES.md | Message types, usage patterns, and code examples |
SESSION_REPORT_DEMO.md | Quota management and usage reporting walkthrough |
3GPP_COMPLIANCE_REPORT.md | Detailed compliance verification and integration testing |
CLAUDE.md | Development commands and codebase architecture |
# Build the library
cargo build
# Run all tests (281+ tests)
cargo test
# Run specific test category
cargo test ie::f_teid # Test F-TEID implementation
cargo test message::heartbeat # Test heartbeat messages
# Check code formatting and linting
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
# Generate documentation
cargo doc --no-deps --document-private-items --all-features
# Test complete session lifecycle
cargo run --example session-server -- --interface lo --port 8805 &
cargo run --example session-client -- --address 127.0.0.1 --sessions 3
# Analyze protocol compliance
cargo run --example pcap-reader -- --pcap captured.pcap --format json --pfcp-only
# Benchmark performance
cargo test --release -- --ignored bench_
// SMF establishing session with UPF
let session_request = SessionEstablishmentRequestBuilder::new(seid, seq)
.node_id(smf_node_id)
.fseid(session_fseid)
.create_pdrs(vec![
// Uplink PDR - match user traffic
CreatePdr::builder()
.pdr_id(PdrId::new(1))
.precedence(Precedence::new(100))
.pdi(uplink_pdi)
.far_id(FarId::new(1))
.build()?,
// Downlink PDR - match network traffic
CreatePdr::builder()
.pdr_id(PdrId::new(2))
.precedence(Precedence::new(200))
.pdi(downlink_pdi)
.far_id(FarId::new(2))
.build()?,
])
.create_fars(vec![
// Uplink FAR - forward to data network
CreateFar::builder()
.far_id(FarId::new(1))
.apply_action(ApplyAction::FORW)
.forwarding_parameters(ForwardingParameters::new(
DestinationInterface::Core,
Some(network_instance)
))
.build()?,
])
.build()?;
// Handle quota exhaustion reports from UPF
match message.msg_type() {
MsgType::SessionReportRequest => {
if let Some(usage_report) = message.find_ie(IeType::UsageReport) {
let triggers = usage_report.usage_report_trigger();
if triggers.contains(UsageReportTrigger::VOLTH) {
println!("๐ Volume quota exhausted for session {:016x}",
message.seid().unwrap());
// Grant additional quota or terminate session
let response = SessionReportResponseBuilder::new(
message.seid().unwrap(),
message.sequence(),
Cause::new(CauseValue::RequestAccepted)
).build()?;
}
}
}
}
We welcome contributions! This library is actively maintained and we're happy to help with:
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Ready to build next-generation 5G networks with Rust? Check out our examples to get started! ๐