rs-pfcp

Crates.iors-pfcp
lib.rsrs-pfcp
version0.1.0
created_at2025-09-25 18:38:11.748107+00
updated_at2025-09-25 18:38:11.748107+00
descriptionHigh-performance Rust implementation of PFCP (Packet Forwarding Control Protocol) for 5G networks with 100% 3GPP TS 29.244 Release 18 compliance
homepagehttps://github.com/xandlom/rs-pfcp
repositoryhttps://github.com/xandlom/rs-pfcp
max_upload_size
id1854970
size10,849,876
Andrey Lomov (xandlom)

documentation

https://docs.rs/rs-pfcp

README

rs-pfcp

Rust Crates.io Documentation License

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.

๐Ÿš€ 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

  • ๐Ÿ† 100% 3GPP TS 29.244 Release 18 Compliance - All 69 Information Elements implemented
  • ๐Ÿ”ฅ High Performance - Zero-copy binary protocol implementation with Rust's memory safety
  • ๐Ÿงช Battle Tested - 281+ comprehensive tests with full round-trip serialization validation
  • ๐Ÿ› ๏ธ Developer Friendly - Builder patterns, structured debugging, and comprehensive error handling
  • ๐Ÿ“Š Production Ready - YAML/JSON message display, network interface support, and robust examples

Protocol Coverage

  • โœ… 23/23 Message Types (100% coverage) - All core session and association management
  • โœ… 69/69 Information Elements (100% coverage) - Complete IE specification
  • โœ… Advanced Features - Network slicing (S-NSSAI), multi-access support, F-TEID with CHOOSE flags
  • โœ… 5G Core Integration - Session establishment, modification, deletion, and usage reporting

๐Ÿƒโ€โ™‚๏ธ Quick Start

Installation

Add to your Cargo.toml:

[dependencies]
rs-pfcp = "0.1.0"

Basic Usage

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
}

Network Examples

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

๐Ÿ—๏ธ Architecture

Core Components

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

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

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

๐Ÿ”ง Development

Build and Test

# 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

Example Workflows

# 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_

๐ŸŒŸ Real-World Usage

5G Network Integration

// 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()?;

Usage Reporting & Quota Management

// 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()?;
            }
        }
    }
}

๐Ÿค 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! ๐Ÿš€

Commit count: 81

cargo fmt