Skip to content

issue 469: Implement Packet Loss Simulation for TQUIC Tools#477

Open
Chi-Kai wants to merge 2 commits intoTencent:developfrom
Chi-Kai:tquic_issue469
Open

issue 469: Implement Packet Loss Simulation for TQUIC Tools#477
Chi-Kai wants to merge 2 commits intoTencent:developfrom
Chi-Kai:tquic_issue469

Conversation

@Chi-Kai
Copy link
Contributor

@Chi-Kai Chi-Kai commented Jul 12, 2025

This PR implements comprehensive packet loss simulation capabilities for TQUIC tools, enabling testing of network resilience and protocol behavior under adverse conditions.

closed #469

Features Implemented

Packet Header Parsing

  • Added packet header parsing interface to extract packet sequence numbers and types
  • Utilizes PacketHeader::from_bytes() for robust packet analysis
  • Supports all QUIC packet types: Initial, ZeroRTT, Handshake, OneRTT, Retry, VersionNegotiation

Packet Loss Simulation

  • Random Loss: Configurable loss rate (0.0 to 1.0) with uniform distribution
  • Specific Packet Numbers: Target exact packet sequence numbers for testing
  • Packet Type Filtering: Drop specific packet types (e.g., handshake packets only)
  • Directional Control: Separate control for incoming vs outgoing packet loss

Command Line Interface

Added new parameters to both tquic_client and tquic_server:

  --packet-loss-rate <RATE>         # Random loss rate (0.0-1.0)
  --packet-loss-numbers <NUMBERS>   # Comma-separated packet numbers
  --packet-loss-types <TYPES>       # Packet types to drop
  --packet-loss-incoming            # Apply to incoming packets  
  --packet-loss-outgoing            # Apply to outgoing packets

Implementation Details

Core Components:

  • tools/src/packet_loss.rs: Main simulation logic and configuration
  • tools/src/common.rs: Integration with QuicSocket for packet interception
  • Updated client/server binaries with CLI parameter support

Integration Points:

  • Receive Path: Intercepts packets in recv_from() before processing
  • Send Path: Intercepts packets in send_to() before transmission
  • Error Handling: Uses WouldBlock to simulate dropped packets gracefully

Usage Examples

# Server with 10% random packet loss
./tquic_server --packet-loss-rate 0.1 --packet-loss-outgoing

# Client dropping handshake packets
./tquic_client --packet-loss-types handshake --packet-loss-outgoing --connect-to 127.0.0.1:8443 https://example.org

# Combined testing with specific packet numbers
./tquic_client --packet-loss-numbers 1,5,10 --packet-loss-incoming --connect-to 127.0.0.1:8443 https://example.org

Test

image

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.72%. Comparing base (b62863a) to head (7325353).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #477   +/-   ##
========================================
  Coverage    94.72%   94.72%           
========================================
  Files           50       50           
  Lines        30282    30282           
========================================
  Hits         28685    28685           
  Misses        1597     1597           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

【腾讯犀牛鸟计划】TQUIC tools支持报文丢失

3 participants