From 0ea1bb578f28591141a68f4c81f9a2cadc131c10 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 31 Jul 2015 08:57:25 -0700 Subject: [PATCH] support max bandwidth in congestion control --- libraries/networking/src/udt/CongestionControl.cpp | 8 ++++++++ libraries/networking/src/udt/CongestionControl.h | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/networking/src/udt/CongestionControl.cpp b/libraries/networking/src/udt/CongestionControl.cpp index 1450e60930..65f358e0bf 100644 --- a/libraries/networking/src/udt/CongestionControl.cpp +++ b/libraries/networking/src/udt/CongestionControl.cpp @@ -112,6 +112,14 @@ void DefaultCC::onACK(SequenceNumber ackNum) { } _packetSendPeriod = (_packetSendPeriod * synInterval()) / (_packetSendPeriod * increase + synInterval()); + + if (_maxBandwidth > 0) { + // anytime the packet send period is about to be increased, make sure it stays below the minimum period, + // calculated based on the maximum desired bandwidth + int minPacketSendPeriod = USECS_PER_SECOND / (double(_maxBandwidth) / _mss); + _packetSendPeriod = std::max(_packetSendPeriod, (double) minPacketSendPeriod); + } + } void DefaultCC::onLoss(SequenceNumber rangeStart, SequenceNumber rangeEnd) { diff --git a/libraries/networking/src/udt/CongestionControl.h b/libraries/networking/src/udt/CongestionControl.h index f8f4860a89..e5af8acac8 100644 --- a/libraries/networking/src/udt/CongestionControl.h +++ b/libraries/networking/src/udt/CongestionControl.h @@ -47,15 +47,16 @@ protected: void setMSS(int mss) { _mss = mss; } void setMaxCongestionWindowSize(int window) { _maxCongestionWindowSize = window; } void setBandwidth(int bandwidth) { _bandwidth = bandwidth; } + void setMaxBandwidth(int maxBandwidth) { _maxBandwidth = maxBandwidth; } void setSendCurrentSequenceNumber(SequenceNumber seqNum) { _sendCurrSeqNum = seqNum; } void setReceiveRate(int rate) { _receiveRate = rate; } void setRTT(int rtt) { _rtt = rtt; } - double _packetSendPeriod { 1.0 }; // Packet sending period, in microseconds double _congestionWindowSize { 16.0 }; // Congestion window size, in packets int _bandwidth { 0 }; // estimated bandwidth, packets per second + int _maxBandwidth { -1 }; // Maximum desired bandwidth, packets per second double _maxCongestionWindowSize { 0.0 }; // maximum cwnd size, in packets int _mss { 0 }; // Maximum Packet Size, including all packet headers