Skip to content

feat(network): Bandwidth Management and QoS — v1.8.0 Issue #190 - #4273

Merged
makr-code merged 3 commits into
developfrom
copilot/add-bandwidth-management-qos
Mar 15, 2026
Merged

makr-code merged 3 commits into
developfrom
copilot/add-bandwidth-management-qos

Conversation

Copilot AI commented Mar 15, 2026 •

Copy link
Copy Markdown
Contributor

Implements all Bandwidth Management and QoS acceptance criteria (Issue #190, v1.8.0) in src/network/. Includes a post-implementation audit that caught and fixed a critical integration gap: the congestion controller existed but never gated sends.

Core additions (include/network/qos_manager.h + src/network/qos_manager.cpp)

  • LeakyBucket — constant-rate shaper (strict drain, no burst accumulation); complements TokenBucket
  • CongestionController — AIMD: slow-start until ssthresh, then additive-increase; recordLoss() halves cwnd; Jacobson/Karels SRTT; cwnd cap at 64 MB
  • QoSManager::Config extended: max_bandwidth_mbps, per_connection_limit_mbps, enable_priority_queuing, starvation_guard_threshold
  • Snake-case API (spec-required): set_priority(), set_bandwidth_limit(), set_token_bucket()
  • Priority queue scheduling: enqueueSend() / dequeueForSend() — strict CRITICAL→HIGH→MEDIUM→LOW with starvation guard that forces a lower-priority dequeue after starvation_guard_threshold consecutive high-priority serves
  • allowSend() hot path now enforces three shaping stages in order: token bucket → leaky bucket → congestion window
  • configureTc(TcConfig) — issues tc qdisc/tc class HTB commands; interface name validated against [a-zA-Z0-9._-] and rejected if leading - (prevents argument injection into tc)
QoSManager::Config cfg;
cfg.max_bandwidth_mbps        = 1000;  // 1 Gbps aggregate
cfg.per_connection_limit_mbps = 100;   // auto-applied on registerConnection()
cfg.enable_priority_queuing   = true;
cfg.starvation_guard_threshold = 16;
QoSManager qos(cfg);

qos.set_priority(conn, Priority::CRITICAL);
qos.set_bandwidth_limit(conn, 50 * 1024 * 1024);  // 50 MB/s → token bucket
qos.setLeakyBucket(conn, 400'000'000, 50'000'000); // 400 Mbps drain, 50 MB cap

// Congestion control
qos.recordAck(conn, bytes_acked, rtt);   // grows cwnd (slow-start / AIMD)
qos.recordLoss(conn);                    // halves cwnd, sets ssthresh

// allowSend() gates on all three: token bucket, leaky bucket, cwnd
bool ok = qos.allowSend(conn, bytes);

Audit fixes (post-implementation)

  • Congestion control was not integrated: CongestionController was tracking cwnd but allowSend() never checked it. Fixed: allowSend() now rejects sends where queue_depth + bytes > cwnd.
  • ConnectionStats lacked CC observability: Added congestion_window, congestion_ssthresh_bytes, smoothed_rtt_us fields populated by getConnectionStats().
  • tc argument injection: configureTc() now also rejects interface names beginning with - to prevent tc flag injection (e.g. -h, --help).

ROADMAP updates

Type of Change

  • Bug fix
  • New feature
  • Refactoring
  • Documentation
  • Other:

Testing

  • Unit tests added/updated — tests/test_bandwidth_management_qos.cpp (40 tests across 8 suites: LeakyBucketTest, PriorityQueueTest, FairQueueStarvationTest, CongestionControllerTest, BandwidthMbpsConfigTest, LinuxTcTest, PriorityLevelsTest, BandwidthQoSTest); all 40 pre-existing QoSManagerFocusedTests continue to pass
  • Integration tests added/updated
  • Manual testing performed

📚 Research & Knowledge (wenn applicable)

  • Diese PR basiert auf wissenschaftlichen Paper(s) oder Best Practices?
    • Falls JA: Research-Dateien in /docs/research/ angelegt?
    • Falls JA: Im Modul-README unter "Wissenschaftliche Grundlagen" verlinkt?
    • Falls JA: In /docs/research/implementation_influence/ eingetragen?

Relevante Quellen:

  • Paper:
  • Best Practice:
  • Architecture Decision:

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No new warnings introduced
Original prompt

This section details on the original issue you should resolve

<issue_title>Bandwidth Management and QoS</issue_title>
<issue_description>### Context

This issue implements the roadmap item 'Bandwidth Management and QoS' for the network domain. It is sourced from the consolidated roadmap under 🟡 Medium Priority — Near-term (v1.5.0 – v1.8.0) and targets milestone v1.8.0.

Primary detail section: Bandwidth Management and QoS

Goal

Deliver the scoped changes for Bandwidth Management and QoS in src/network/ and complete the linked detail section in a release-ready state for v1.8.0.

Detailed Scope

Bandwidth Management and QoS

Priority: Medium
Target Version: v1.8.0

Add bandwidth management and quality of service (QoS) features.

Features:

  • Per-connection bandwidth limits
  • Traffic shaping (token bucket, leaky bucket)
  • Priority queuing (high/medium/low)
  • Fair queuing (prevent starvation)
  • Congestion control integration

API:

QoSManager::Config config;
config.max_bandwidth_mbps = 1000;  // 1 Gbps total
config.per_connection_limit_mbps = 100;  // 100 Mbps per connection
config.enable_fair_queuing = true;
config.enable_priority_queuing = true;

QoSManager qos(config);

// Set connection priority
qos.set_priority(connection_id, Priority::HIGH);

// Set bandwidth limit
qos.set_bandwidth_limit(connection_id, 50 * 1024 * 1024);  // 50 Mbps

// Traffic shaping with token bucket
qos.set_token_bucket(connection_id, 
    /*rate=*/10'000'000,    // 10 MB/s
    /*burst=*/100'000'000   // 100 MB burst
);

Priority Levels:

  • CRITICAL: Interactive queries, low latency required
  • HIGH: Transactional operations, OLTP
  • MEDIUM: Analytical queries, OLAP
  • LOW: Batch operations, backups, replication

Implementation:

  • Token bucket algorithm for rate limiting
  • Priority queue for packet scheduling
  • Fair queuing to prevent starvation
  • Integration with Linux tc (traffic control)

Acceptance Criteria

  • Per-connection bandwidth limits
  • Traffic shaping (token bucket, leaky bucket)
  • Priority queuing (high/medium/low)
  • Fair queuing (prevent starvation)
  • Congestion control integration
  • CRITICAL: Interactive queries, low latency required
  • HIGH: Transactional operations, OLTP
  • MEDIUM: Analytical queries, OLAP
  • LOW: Batch operations, backups, replication
  • Token bucket algorithm for rate limiting
  • Priority queue for packet scheduling
  • Fair queuing to prevent starvation
  • Integration with Linux tc (traffic control)

Relationships

References

  • src/ROADMAP.md
  • src/network/FUTURE_ENHANCEMENTS.md#bandwidth-management-and-qos
  • Source key: roadmap:190:network:v1.8.0:bandwidth-management-and-qos

Generated from the consolidated source roadmap. Keep the roadmap and issue in sync when scope changes.

</issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

…190)

- Add LeakyBucket class: constant-rate traffic shaper with overflow detection
- Add CongestionController class: AIMD (slow-start + additive-increase/multiplicative-decrease)
- Extend QoSManager::Config: max_bandwidth_mbps, per_connection_limit_mbps, enable_priority_queuing, starvation_guard_threshold
- Add snake_case API: set_priority(), set_bandwidth_limit(), set_token_bucket()
- Add leaky bucket integration: setLeakyBucket() / clearLeakyBucket()
- Add priority queue scheduling: enqueueSend() / dequeueForSend() / getPendingQueueDepth()
- Add fair-queuing starvation guard in dequeueForSend()
- Add congestion control: recordAck() / recordLoss() / getCongestionWindow()
- Add Linux tc integration: configureTc(TcConfig) with interface name injection prevention
- allowSend() now also checks leaky bucket conformance
- Add 37 focused tests in test_bandwidth_management_qos.cpp
- Add CI workflow: bandwidth-management-qos-ci.yml

Co-authored-by: makr-code <[email protected]>
Copilot AI changed the title [WIP] Implement bandwidth management and QoS features feat(network): Bandwidth Management and QoS (v1.8.0, Issue #190) Mar 15, 2026
Copilot AI requested a review from makr-code March 15, 2026 19:03
…nStats CC fields, ROADMAP updates, tc argument injection prevention

- allowSend() now gates sends on CongestionController cwnd (congestion control integration)
- ConnectionStats: add congestion_window, congestion_ssthresh_bytes, smoothed_rtt_us fields
- getConnectionStats() populates new CC fields
- configureTc(): reject interface names starting with '-' to prevent tc argument injection
- 3 new tests: AllowSendBlockedByCongestionWindow, AllowSendAfterWindowDrainedIsPermitted, ConnectionStatsExposesCC
- LinuxTcTest: add dash-prefix injection test cases
- src/network/ROADMAP.md: mark Bandwidth Management and QoS done with full detail
- src/ROADMAP.md: row #190 marked ✅
- src/network/FUTURE_ENHANCEMENTS.md: section updated with implementation status

Co-authored-by: makr-code <[email protected]>
Copilot AI changed the title feat(network): Bandwidth Management and QoS (v1.8.0, Issue #190) feat(network): Bandwidth Management and QoS — v1.8.0 Issue #190 Mar 15, 2026
@makr-code
makr-code marked this pull request as ready for review March 15, 2026 19:26
@makr-code
makr-code merged commit 4195f81 into develop Mar 15, 2026
11 checks passed
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.

Bandwidth Management and QoS

2 participants