TCP congestion control first draft

This commit is contained in:
Atlante45 2016-09-20 17:29:31 -07:00 committed by Stephen Birarda
parent 5e697462ef
commit bad96d54ea
5 changed files with 129 additions and 2 deletions

View file

@ -24,6 +24,7 @@
#include "../HifiSockAddr.h"
#include "CongestionControl.h"
#include "Connection.h"
#include "TCPRenoCC.h"
//#define UDT_CONNECTION_DEBUG
@ -131,7 +132,7 @@ private:
int _maxBandwidth { -1 };
std::unique_ptr<CongestionControlVirtualFactory> _ccFactory { new CongestionControlFactory<DefaultCC>() };
std::unique_ptr<CongestionControlVirtualFactory> _ccFactory { new CongestionControlFactory<TCPRenoCC>() };
friend UDTTest;
};

View file

@ -0,0 +1,84 @@
//
// TCPRenoCC.cpp
// libraries/networking/src/udt
//
// Created by Clement on 9/20/16.
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "TCPRenoCC.h"
using namespace udt;
void TCPRenoCC::init() {
_slowStart = true;
_issThreshold = 83333;
_packetSendPeriod = 0.0;
_congestionWindowSize = 2.0;
setAckInterval(2);
setRTO(1000000);
}
void TCPRenoCC::onACK(SequenceNumber ackNum) {
if (ackNum == _lastACK) {
if (3 == ++_duplicateAckCount) {
duplicateACKAction();
} else if (_duplicateAckCount > 3) {
_congestionWindowSize += 1.0;
} else {
ackAction();
}
} else {
if (_duplicateAckCount >= 3) {
_congestionWindowSize = _issThreshold;
}
_lastACK = ackNum;
_duplicateAckCount = 1;
ackAction();
}
}
void TCPRenoCC::onTimeout() {
_issThreshold = seqlen(_lastACK, _sendCurrSeqNum) / 2;
if (_issThreshold < 2) {
_issThreshold = 2;
}
_slowStart = true;
_congestionWindowSize = 2.0;
}
void TCPRenoCC::ackAction() {
if (_slowStart) {
_congestionWindowSize += 1.0;
if (_congestionWindowSize >= _issThreshold) {
_slowStart = false;
}
} else {
_congestionWindowSize += 1.0 / _congestionWindowSize;
}
}
void TCPRenoCC::duplicateACKAction() {
_slowStart = false;
_issThreshold = seqlen(_lastACK, _sendCurrSeqNum) / 2;
if (_issThreshold < 2) {
_issThreshold = 2;
}
_congestionWindowSize = _issThreshold + 3;
}
void TCPRenoCC::setInitialSendSequenceNumber(SequenceNumber seqNum) {
_lastACK = seqNum - 1;
}

View file

@ -0,0 +1,40 @@
//
// TCPRenoCC.h
// libraries/networking/src/udt
//
// Created by Clement on 9/20/16.
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_TCPRenoCC_h
#define hifi_TCPRenoCC_h
#include "CongestionControl.h"
namespace udt {
class TCPRenoCC : public CongestionControl {
public:
virtual void init();
virtual void onACK(SequenceNumber ackNum);
virtual void onTimeout();
protected:
virtual void ackAction();
virtual void duplicateACKAction();
virtual void setInitialSendSequenceNumber(SequenceNumber seqNum);
int _issThreshold;
bool _slowStart;
int _duplicateAckCount;
SequenceNumber _lastACK;
};
}
#endif // hifi_TCPRenoCC_h

View file

@ -18,10 +18,12 @@
#include <QtCore/QElapsedTimer>
#include <QtCore/QLoggingCategory>
#include <QtCore/QRegularExpression>
#include <QtCore/QSettings>
#include <QtCore/QTimer>
#include <QtCore/QThread>
#include <QtCore/QThreadPool>
#include <QtGui/QGuiApplication>
#include <QtGui/QResizeEvent>
#include <QtGui/QWindow>

View file

@ -25,7 +25,7 @@ const QCommandLineOption TARGET_OPTION {
"IP:PORT or HOSTNAME:PORT"
};
const QCommandLineOption PACKET_SIZE {
"packet-size", "size for sent packets in bytes (defaults to " + QString(MAX_PACKET_SIZE) + ")", "bytes",
"packet-size", "size for sent packets in bytes (defaults to " + QString(udt::MAX_PACKET_SIZE) + ")", "bytes",
QString(udt::MAX_PACKET_SIZE)
};
const QCommandLineOption MIN_PACKET_SIZE {