Skip to content

Add TCP protocol support with congestion control#1

Open
sarsanaee wants to merge 1 commit intomainfrom
claude/create-tcp-branch-qZvSq
Open

Add TCP protocol support with congestion control#1
sarsanaee wants to merge 1 commit intomainfrom
claude/create-tcp-branch-qZvSq

Conversation

@sarsanaee
Copy link
Collaborator

Summary

This PR adds comprehensive TCP (Transmission Control Protocol) support to the juggler networking library, including TCP header definitions, flow key structures, and a complete TCP congestion control implementation following RFC 5681 standards.

Key Changes

TCP Header Implementation

  • Added tcp.h with complete TCP header structure (RFC 793) including:
    • TCP header fields (ports, sequence/acknowledgment numbers, flags, window, checksum)
    • Port wrapper struct for consistency with UDP
    • Control flag definitions (FIN, SYN, RST, PSH, ACK, URG, ECE, CWR)
    • Helper methods for flag manipulation and header length calculation
    • String conversion methods for debugging (ToString(), FlagsToString())
  • Added tcp.cc with implementations of string conversion methods

TCP Congestion Control

  • Added tcp_cc.h with full TCP congestion control implementation:
    • Sequence number handling: Proper wrap-around comparison functions for 32-bit sequence numbers
    • TCP states: All 11 RFC 793 connection states (CLOSED, LISTEN, SYN_SENT, etc.)
    • Congestion control states: Slow Start, Congestion Avoidance, Fast Recovery
    • RTT estimation: Jacobson/Karels algorithm (RFC 6298) with RTO calculation
    • TcpControlBlock: Protocol Control Block managing:
      • Send/receive sequence variables
      • Congestion window (cwnd) and slow start threshold (ssthresh)
      • Fast retransmit/recovery with NewReno algorithm
      • SACK (Selective Acknowledgment) support
      • RTO timer management with exponential backoff
      • Comprehensive statistics tracking

Flow Key Structures

  • Extended flow_key.h with TCP-specific flow definitions:
    • Added Protocol enum for transport layer identification (UDP/TCP)
    • Added tcp_flow::Listener struct for TCP listener endpoints
    • Added tcp_flow::Key struct for TCP 5-tuple flow identification
    • Added hash specializations for both TCP flow structures

Notable Implementation Details

  • RFC Compliance: Implements RFC 5681 (TCP Congestion Control), RFC 6298 (RTO calculation), and RFC 793 (TCP specification)
  • Sequence Number Wrap-around: Uses signed arithmetic for proper comparison across 32-bit boundaries
  • Initial Window: Uses RFC 6928 recommended initial congestion window (10 MSS)
  • Fast Recovery: NewReno-style recovery with partial ACK handling
  • SACK Support: Framework for up to 4 SACK blocks per ACK
  • Configurable MSS: Default 1460 bytes with update capability
  • Comprehensive Logging: String conversion methods for debugging connection state and congestion control behavior

Testing Considerations

  • TCP header size validated at compile-time (20 bytes)
  • Flow key sizes validated (12 bytes for both UDP and TCP)
  • All congestion control state transitions follow RFC specifications

https://claude.ai/code/session_01FawDCUwRcn1X6wwsfGjfxC

This commit introduces TCP transport protocol support to the Machnet
networking stack, which previously only supported UDP. The implementation
includes:

- tcp.h: TCP header structure with standard fields (ports, seq/ack numbers,
  flags, window, checksum, urgent pointer) following RFC 793
- tcp.cc: TCP header ToString() and FlagsToString() utility methods
- tcp_cc.h: TCP congestion control with:
  - Slow start (exponential cwnd growth)
  - Congestion avoidance (AIMD)
  - Fast retransmit (on 3 duplicate ACKs)
  - Fast recovery (NewReno-style)
  - RTT estimation using Jacobson/Karels algorithm
  - RTO calculation per RFC 6298
  - SACK support
- tcp_flow.h: TCP flow management including:
  - Full TCP state machine (CLOSED through TIME_WAIT)
  - Three-way handshake (active and passive open)
  - Connection teardown with FIN/RST
  - Data transmission with congestion control
  - Out-of-order packet handling and reassembly
- flow_key.h: Extended to support TCP flow keys alongside existing UDP

The implementation follows the existing code style and integrates with
the DPDK-based packet processing infrastructure.

https://claude.ai/code/session_01FawDCUwRcn1X6wwsfGjfxC
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.

2 participants

Comments