rs-pfcp
A high-performance Rust implementation of the PFCP (Packet Forwarding Control Protocol) for 5G networks, providing comprehensive compliance with 3GPP TS 29.244 Release 18 specification.
๐ What is PFCP?
PFCP is the critical communication protocol between Control Plane and User Plane functions in 5G networks:
- SMF (Session Management Function) โ UPF (User Plane Function)
- Manages packet forwarding rules, traffic steering, and usage reporting
- Essential for 5G service orchestration, QoS enforcement, and network slicing
โจ Key Features
- ๐ 3GPP TS 29.244 Release 18 Compliance - 259+ Information Elements implemented with complete core session management
- ๐ฅ High Performance - Sub-microsecond binary protocol implementation
- ๐งช Battle Tested - 3,023+ comprehensive tests with full round-trip serialization validation
- ๐ ๏ธ Developer Friendly - Ergonomic builder APIs with convenience methods and direct marshaling
- ๐ Production Ready - Message comparison, YAML/JSON display, network interface support, and robust examples
Ergonomic Builder API
Build and send PFCP messages in just 2-3 lines:
// Session responses with convenience methods
let response = accepted
.fseid
.marshal?;
// Or with cause values
let response = new
.cause_accepted
.marshal;
// Requests with type-safe builders
let request = new
.node_id
.recovery_time_stamp
.marshal;
// IntoIe tuple conversions for common IEs
use IntoIe;
let fseid_ie = .into_ie; // F-SEID from tuple
let fteid_ie = .into_ie; // F-TEID from tuple
let ue_ip_ie = .into_ie; // UE IP dual-stack
// Iterator-based IE access
for pdr in msg.ies
let first_fseid = msg.ies.next;
let pdr_count = msg.ies.count;
// Typed IE decoding with Ie::parse<T>()
let pdr_id: PdrId = msg.ies.next?.parse?;
let cause: Cause = msg.ies.next?.parse?;
Protocol Coverage
- โ 25/25 Message Types (100% coverage) - All core session and association management
- โ 259+ Information Elements implemented (334+ enum variants defined) - Complete 3GPP TS 29.244 Release 18 core IEs
- โ Advanced Features - Network slicing (S-NSSAI), multi-access support, F-TEID with CHOOSE flags, QoS enforcement, usage reporting, Ethernet PDU sessions
- โ 5G Core Integration - Session establishment, modification, deletion, and comprehensive usage reporting with quota management
๐โโ๏ธ Quick Start
Installation
Add to your Cargo.toml:
[]
= "0.3.0"
Basic Usage
use SessionEstablishmentRequestBuilder;
use SessionEstablishmentResponseBuilder;
use Ipv4Addr;
// Create a session establishment request with ergonomic builders
let request_bytes = new
.node_id // Direct IP address
.fseid // SEID + IP
.create_pdrs
.create_fars
.marshal?; // Direct marshaling
// Send over network
socket.send?;
// Parse received messages and respond
let parsed_msg = parse?;
match parsed_msg.msg_type
Message Comparison & Validation
use MessageComparator;
// Test mode - ignore transient fields (sequence, timestamps)
let result = new
.test_mode
.compare?;
if result.is_match else
// Semantic comparison with timestamp tolerance
let result = new
.semantic_mode // Compare F-TEID, UE IP by meaning
.timestamp_tolerance // 5 second tolerance
.ignore_sequence
.compare?;
// Generate detailed diff
let result = new
.generate_diff
.compare?;
if let Some = result.diff
Features:
- Multiple comparison modes - Strict, semantic, test, and audit presets
- Semantic comparison - F-TEID, UE IP Address compared by function, not bytes
- Timestamp tolerance - Configurable window for timestamp comparison
- Flexible IE filtering - Ignore specific IEs, focus on subsets, or handle timestamps
- Detailed reporting - Match statistics, mismatch details, YAML diffs
Network Examples
The library includes comprehensive examples for real-world scenarios:
# Run PFCP heartbeat server
# Run session client connecting to UPF
# Analyze captured PFCP traffic
# Demo message comparison and validation
# Run performance benchmarks
๐๏ธ Architecture
Core Components
rs-pfcp/
โโโ src/ie/ # Information Elements (139+ 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
โ โโโ ethernet_*.rs # Ethernet PDU session support (10 IEs)
โ โโโ ...
โโโ src/message/ # PFCP Messages (25 types)
โ โโโ session_*.rs # Session lifecycle management
โ โโโ association_*.rs # Node association handling
โ โโโ heartbeat.rs # Keep-alive mechanism
โโโ src/comparison/ # Message comparison framework
โ โโโ builder.rs # Fluent comparison API
โ โโโ semantic.rs # Semantic comparison (F-TEID, UE IP, timestamps)
โ โโโ options.rs # Configuration options
โ โโโ result.rs # Result types and statistics
โโโ examples/ # Production-ready examples
โโโ session-server/ # UPF simulator
โโโ session-client/ # SMF simulator
โโโ pcap-reader/ # Traffic analysis tool
Key Design Principles
- Type Safety - Rust's type system prevents protocol errors at compile time
- Zero Copy - Efficient binary serialization without unnecessary allocations
- Builder Patterns - Intuitive construction of complex PFCP messages
- Error Handling - Comprehensive error types with proper cause codes
- Testing - Every marshal/unmarshal operation verified with round-trip tests
๐ Documentation
Quick Links
| Document | Purpose |
|---|---|
| Documentation Hub | Complete documentation index |
| API Guide | Comprehensive API reference and usage patterns |
| Comparison Guide | Message comparison, testing, and validation |
| IE Support | Complete Information Element implementation status |
| Messages Reference | Message types, usage patterns, and code examples |
| Examples Guide | Running and understanding example applications |
Guides & Tutorials
- Comparison Guide - Testing and validating PFCP messages
- Deployment Guide - Production deployment strategies
- Session Report Demo - Quota management walkthrough
- Git Hooks Setup - Development workflow automation
Reference Documentation
- 3GPP Compliance - Detailed compliance verification
- IE Compliance - Information Element compliance details
- API Documentation - Full API reference on docs.rs
๐ API Stability
rs-pfcp is currently pre-1.0 (version 0.3.x), meaning the API may change between minor versions. We follow Semantic Versioning and document all breaking changes in the CHANGELOG.
Current Status:
- Version: 0.3.0
- MSRV: Rust 1.87.0
- Spec Compliance: 3GPP TS 29.244 Release 18
- Stability: Pre-1.0 (API evolving)
Upgrade Guide
When upgrading between versions:
- Check CHANGELOG.md for breaking changes
- Run
cargo update -p rs-pfcp - Fix compiler errors (we prefer compile-time breaks over runtime breaks)
- Test your integration
For detailed API stability guarantees and version roadmap, see docs/API-STABILITY.md.
Writing Future-Proof Code
โ DO: Use builder patterns, trait methods, and public constructors โ DON'T: Access struct fields directly or depend on internal modules
We provide migration guides for all breaking changes and deprecate features before removing them.
๐ง Development
Build and Test
# Build the library
# Run all tests (2,800+ tests)
# Run specific test category
# Run performance benchmarks
# Check code formatting and linting
# Generate documentation
Example Workflows
# Test complete session lifecycle
&
# Analyze protocol compliance
# Benchmark performance
Cross-Language Interoperability Testing
Go interoperability tests (using go-pfcp) live in a separate repository: github.com/xandlom/go-pfcp-interop
It verifies cross-compatibility between rs-pfcp (Rust) and Go PFCP implementations:
- Association Setup/Release between Rust and Go stacks
- Complete session lifecycle (establish, modify, report, delete)
- Binary protocol compatibility and 3GPP TS 29.244 compliance
๐ Real-World Usage
The library covers the full 5G session lifecycle: PDR/FAR construction with grouped IE builders, usage reporting with quota triggers, Ethernet PDU sessions, and network slicing (S-NSSAI). See docs/guides/api-guide.md for complete examples and examples/session-client/ for a working SMF simulator.
๐ค Contributing
We welcome contributions! This library is actively maintained and we're happy to help with:
- ๐ Bug Reports - Protocol compliance issues, performance problems
- ๐ก Feature Requests - Additional 3GPP features, improved APIs
- ๐ Documentation - Examples, tutorials, architectural guides
- ๐งช Testing - Real-world scenarios, edge cases, performance benchmarks
๐ License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
๐ Acknowledgments
- Inspired by the excellent go-pfcp library
- Built according to 3GPP TS 29.244 Release 18 specification
- Developed with โค๏ธ for the 5G networking community
Ready to build next-generation 5G networks with Rust? Check out our examples to get started! ๐