From c2d39f0f6afe5e1c40009ffccc194ead8c016896 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 31 Jul 2015 09:02:43 -0700 Subject: [PATCH] make packet send period update respect max bandwidth --- .../networking/src/udt/CongestionControl.cpp | 21 +++++++++++-------- .../networking/src/udt/CongestionControl.h | 1 + 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/libraries/networking/src/udt/CongestionControl.cpp b/libraries/networking/src/udt/CongestionControl.cpp index 65f358e0bf..984d520d07 100644 --- a/libraries/networking/src/udt/CongestionControl.cpp +++ b/libraries/networking/src/udt/CongestionControl.cpp @@ -17,6 +17,17 @@ using namespace std::chrono; static const double USECS_PER_SECOND = 1000000.0; +void CongestionControl::setPacketSendPeriod(double newSendPeriod) { + 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(newSendPeriod, (double) minPacketSendPeriod); + } else { + _packetSendPeriod = newSendPeriod; + } +} + void DefaultCC::init() { _lastRCTime = high_resolution_clock::now(); @@ -111,15 +122,7 @@ 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); - } - + setPacketSendPeriod((_packetSendPeriod * synInterval()) / (_packetSendPeriod * increase + synInterval())); } void DefaultCC::onLoss(SequenceNumber rangeStart, SequenceNumber rangeEnd) { diff --git a/libraries/networking/src/udt/CongestionControl.h b/libraries/networking/src/udt/CongestionControl.h index e5af8acac8..75970ed2fd 100644 --- a/libraries/networking/src/udt/CongestionControl.h +++ b/libraries/networking/src/udt/CongestionControl.h @@ -51,6 +51,7 @@ protected: void setSendCurrentSequenceNumber(SequenceNumber seqNum) { _sendCurrSeqNum = seqNum; } void setReceiveRate(int rate) { _receiveRate = rate; } void setRTT(int rtt) { _rtt = rtt; } + void setPacketSendPeriod(double newSendPeriod); // call this internally to ensure send period doesn't go past max bandwidth double _packetSendPeriod { 1.0 }; // Packet sending period, in microseconds double _congestionWindowSize { 16.0 }; // Congestion window size, in packets