Merge branch 'atp' of https://github.com/birarda/hifi into protocol

This commit is contained in:
Atlante45 2015-08-03 12:12:45 -07:00
commit efb04fac21
4 changed files with 47 additions and 106 deletions

View file

@ -95,7 +95,7 @@ void Connection::recordSentPackets(int dataSize, int payloadSize) {
} }
void Connection::recordRetransmission() { void Connection::recordRetransmission() {
_stats.recordRetransmission(); _stats.record(ConnectionStats::Stats::Retransmission);
} }
void Connection::sendACK(bool wasCausedBySyncTimeout) { void Connection::sendACK(bool wasCausedBySyncTimeout) {
@ -175,7 +175,7 @@ void Connection::sendACK(bool wasCausedBySyncTimeout) {
// reset the number of data packets received since last ACK // reset the number of data packets received since last ACK
_packetsSinceACK = 0; _packetsSinceACK = 0;
_stats.recordSentACK(); _stats.record(ConnectionStats::Stats::SentACK);
} }
void Connection::sendLightACK() { void Connection::sendLightACK() {
@ -199,7 +199,7 @@ void Connection::sendLightACK() {
// have the socket send off our packet immediately // have the socket send off our packet immediately
_parentSocket->writeBasePacket(*lightACKPacket, _destination); _parentSocket->writeBasePacket(*lightACKPacket, _destination);
_stats.recordSentLightACK(); _stats.record(ConnectionStats::Stats::SentLightACK);
} }
void Connection::sendACK2(SequenceNumber currentACKSubSequenceNumber) { void Connection::sendACK2(SequenceNumber currentACKSubSequenceNumber) {
@ -219,7 +219,7 @@ void Connection::sendACK2(SequenceNumber currentACKSubSequenceNumber) {
// update the last sent ACK2 and the last ACK2 send time // update the last sent ACK2 and the last ACK2 send time
_lastSentACK2 = currentACKSubSequenceNumber; _lastSentACK2 = currentACKSubSequenceNumber;
_stats.recordSentACK2(); _stats.record(ConnectionStats::Stats::SentACK2);
} }
void Connection::sendNAK(SequenceNumber sequenceNumberRecieved) { void Connection::sendNAK(SequenceNumber sequenceNumberRecieved) {
@ -240,7 +240,7 @@ void Connection::sendNAK(SequenceNumber sequenceNumberRecieved) {
// record our last NAK time // record our last NAK time
_lastNAKTime = high_resolution_clock::now(); _lastNAKTime = high_resolution_clock::now();
_stats.recordSentNAK(); _stats.record(ConnectionStats::Stats::SentNAK);
} }
void Connection::sendTimeoutNAK() { void Connection::sendTimeoutNAK() {
@ -257,7 +257,7 @@ void Connection::sendTimeoutNAK() {
// record this as the last NAK time // record this as the last NAK time
_lastNAKTime = high_resolution_clock::now(); _lastNAKTime = high_resolution_clock::now();
_stats.recordSentTimeoutNAK(); _stats.record(ConnectionStats::Stats::SentTimeoutNAK);
} }
} }
@ -332,7 +332,7 @@ bool Connection::processReceivedSequenceNumber(SequenceNumber sequenceNumber, in
} }
if (wasDuplicate) { if (wasDuplicate) {
_stats.recordDuplicates(); _stats.record(ConnectionStats::Stats::Duplicate);
} else { } else {
_stats.recordReceivedPackets(payloadSize, packetSize); _stats.recordReceivedPackets(payloadSize, packetSize);
} }
@ -386,6 +386,9 @@ void Connection::processACK(std::unique_ptr<ControlPacket> controlPacket) {
SequenceNumber ack; SequenceNumber ack;
controlPacket->readPrimitive(&ack); controlPacket->readPrimitive(&ack);
// update the total count of received ACKs
_stats.record(ConnectionStats::Stats::ReceivedACK);
// validate that this isn't a BS ACK // validate that this isn't a BS ACK
if (ack > getSendQueue().getCurrentSequenceNumber()) { if (ack > getSendQueue().getCurrentSequenceNumber()) {
// in UDT they specifically break the connection here - do we want to do anything? // in UDT they specifically break the connection here - do we want to do anything?
@ -449,8 +452,7 @@ void Connection::processACK(std::unique_ptr<ControlPacket> controlPacket) {
_congestionControl->onACK(ack); _congestionControl->onACK(ack);
}); });
// update the total count of received ACKs _stats.record(ConnectionStats::Stats::ProcessedACK);
_stats.recordReceivedACK();
} }
void Connection::processLightACK(std::unique_ptr<ControlPacket> controlPacket) { void Connection::processLightACK(std::unique_ptr<ControlPacket> controlPacket) {
@ -470,7 +472,7 @@ void Connection::processLightACK(std::unique_ptr<ControlPacket> controlPacket) {
getSendQueue().ack(ack); getSendQueue().ack(ack);
} }
_stats.recordReceivedLightACK(); _stats.record(ConnectionStats::Stats::ReceivedLightACK);
} }
void Connection::processACK2(std::unique_ptr<ControlPacket> controlPacket) { void Connection::processACK2(std::unique_ptr<ControlPacket> controlPacket) {
@ -508,7 +510,7 @@ void Connection::processACK2(std::unique_ptr<ControlPacket> controlPacket) {
// erase this sub-sequence number and anything below it now that we've gotten our timing information // erase this sub-sequence number and anything below it now that we've gotten our timing information
_sentACKs.erase(_sentACKs.begin(), it); _sentACKs.erase(_sentACKs.begin(), it);
_stats.recordReceivedACK2(); _stats.record(ConnectionStats::Stats::ReceivedACK2);
} }
void Connection::processNAK(std::unique_ptr<ControlPacket> controlPacket) { void Connection::processNAK(std::unique_ptr<ControlPacket> controlPacket) {
@ -530,7 +532,7 @@ void Connection::processNAK(std::unique_ptr<ControlPacket> controlPacket) {
_congestionControl->onLoss(start, end); _congestionControl->onLoss(start, end);
}); });
_stats.recordReceivedNAK(); _stats.record(ConnectionStats::Stats::ReceivedNAK);
} }
void Connection::processTimeoutNAK(std::unique_ptr<ControlPacket> controlPacket) { void Connection::processTimeoutNAK(std::unique_ptr<ControlPacket> controlPacket) {
@ -540,7 +542,7 @@ void Connection::processTimeoutNAK(std::unique_ptr<ControlPacket> controlPacket)
// we don't tell the congestion control object there was loss here - this matches UDTs implementation // we don't tell the congestion control object there was loss here - this matches UDTs implementation
// a possible improvement would be to tell it which new loss this timeout packet told us about // a possible improvement would be to tell it which new loss this timeout packet told us about
_stats.recordReceivedTimeoutNAK(); _stats.record(ConnectionStats::Stats::ReceivedTimeoutNAK);
} }
void Connection::updateRTT(int rtt) { void Connection::updateRTT(int rtt) {

View file

@ -31,57 +31,11 @@ ConnectionStats::Stats ConnectionStats::sample() {
return sample; return sample;
} }
void ConnectionStats::recordSentACK() { void ConnectionStats::record(Stats::Event event) {
++_currentSample.sentACKs; ++_currentSample.events[(int) event];
++_total.sentACKs; ++_total.events[(int) event];
} }
void ConnectionStats::recordReceivedACK() {
++_currentSample.receivedACKs;
++_total.receivedACKs;
}
void ConnectionStats::recordSentLightACK() {
++_currentSample.sentLightACKs;
++_total.sentLightACKs;
}
void ConnectionStats::recordReceivedLightACK() {
++_currentSample.receivedLightACKs;
++_total.receivedLightACKs;
}
void ConnectionStats::recordSentACK2() {
++_currentSample.sentACK2s;
++_total.sentACK2s;
}
void ConnectionStats::recordReceivedACK2() {
++_currentSample.receivedACK2s;
++_total.receivedACK2s;
}
void ConnectionStats::recordSentNAK() {
++_currentSample.sentNAKs;
++_total.sentNAKs;
}
void ConnectionStats::recordReceivedNAK() {
++_currentSample.receivedNAKs;
++_total.receivedNAKs;
}
void ConnectionStats::recordSentTimeoutNAK() {
++_currentSample.sentTimeoutNAKs;
++_total.sentTimeoutNAKs;
}
void ConnectionStats::recordReceivedTimeoutNAK() {
++_currentSample.receivedTimeoutNAKs;
++_total.receivedTimeoutNAKs;
}
void ConnectionStats::recordSentPackets(int payload, int total) { void ConnectionStats::recordSentPackets(int payload, int total) {
++_currentSample.sentPackets; ++_currentSample.sentPackets;
++_total.sentPackets; ++_total.sentPackets;
@ -126,16 +80,6 @@ void ConnectionStats::recordUnreliableReceivedPackets(int payload, int total) {
_total.recievedUnreliableBytes += total; _total.recievedUnreliableBytes += total;
} }
void ConnectionStats::recordRetransmission() {
++_currentSample.retransmissions;
++_total.retransmissions;
}
void ConnectionStats::recordDuplicates() {
++_currentSample.duplicates;
++_total.duplicates;
}
static const double EWMA_CURRENT_SAMPLE_WEIGHT = 0.125; static const double EWMA_CURRENT_SAMPLE_WEIGHT = 0.125;
static const double EWMA_PREVIOUS_SAMPLES_WEIGHT = 1 - 0.125; static const double EWMA_PREVIOUS_SAMPLES_WEIGHT = 1 - 0.125;

View file

@ -13,6 +13,7 @@
#define hifi_ConnectionStats_h #define hifi_ConnectionStats_h
#include <chrono> #include <chrono>
#include <vector>
namespace udt { namespace udt {
@ -22,18 +23,26 @@ public:
std::chrono::microseconds startTime; std::chrono::microseconds startTime;
std::chrono::microseconds endTime; std::chrono::microseconds endTime;
// Control Packet stat collection enum Event {
int sentACKs { 0 }; SentACK,
int receivedACKs { 0 }; ReceivedACK,
int sentLightACKs { 0 }; ProcessedACK,
int receivedLightACKs { 0 }; SentLightACK,
int sentACK2s { 0 }; ReceivedLightACK,
int receivedACK2s { 0 }; SentACK2,
int sentNAKs { 0 }; ReceivedACK2,
int receivedNAKs { 0 }; SentNAK,
int sentTimeoutNAKs { 0 }; ReceivedNAK,
int receivedTimeoutNAKs { 0 }; SentTimeoutNAK,
ReceivedTimeoutNAK,
Retransmission,
Duplicate
};
// construct a vector for the events of the size of our Enum - default value is zero
std::vector<int> events = std::vector<int>((int) Event::Duplicate + 1, 0);
// packet counts and sizes
int sentPackets { 0 }; int sentPackets { 0 };
int recievedPackets { 0 }; int recievedPackets { 0 };
int sentUtilBytes { 0 }; int sentUtilBytes { 0 };
@ -47,9 +56,6 @@ public:
int recievedUnreliableUtilBytes { 0 }; int recievedUnreliableUtilBytes { 0 };
int sentUnreliableBytes { 0 }; int sentUnreliableBytes { 0 };
int recievedUnreliableBytes { 0 }; int recievedUnreliableBytes { 0 };
int retransmissions { 0 };
int duplicates { 0 };
// the following stats are trailing averages in the result, not totals // the following stats are trailing averages in the result, not totals
int sendRate { 0 }; int sendRate { 0 };
@ -65,16 +71,7 @@ public:
Stats sample(); Stats sample();
Stats getTotalStats(); Stats getTotalStats();
void recordSentACK(); void record(Stats::Event event);
void recordReceivedACK();
void recordSentLightACK();
void recordReceivedLightACK();
void recordSentACK2();
void recordReceivedACK2();
void recordSentNAK();
void recordReceivedNAK();
void recordSentTimeoutNAK();
void recordReceivedTimeoutNAK();
void recordSentPackets(int payload, int total); void recordSentPackets(int payload, int total);
void recordReceivedPackets(int payload, int total); void recordReceivedPackets(int payload, int total);
@ -82,9 +79,6 @@ public:
void recordUnreliableSentPackets(int payload, int total); void recordUnreliableSentPackets(int payload, int total);
void recordUnreliableReceivedPackets(int payload, int total); void recordUnreliableReceivedPackets(int payload, int total);
void recordRetransmission();
void recordDuplicates();
void recordSendRate(int sample); void recordSendRate(int sample);
void recordReceiveRate(int sample); void recordReceiveRate(int sample);
void recordEstimatedBandwidth(int sample); void recordEstimatedBandwidth(int sample);

View file

@ -43,7 +43,7 @@ const QCommandLineOption UNRELIABLE_PACKETS {
const QStringList STATS_TABLE_HEADERS { const QStringList STATS_TABLE_HEADERS {
"Send Rate (P/s)", "RTT(ms)", "CW (P)", "Send Period (us)", "Send Rate (P/s)", "RTT(ms)", "CW (P)", "Send Period (us)",
"Received ACK", "Received LACK", "Received NAK", "Received TNAK", "Received ACK", "Processed ACK", "Received LACK", "Received NAK", "Received TNAK",
"Sent ACK2", "Re-sent Packets" "Sent ACK2", "Re-sent Packets"
}; };
@ -228,12 +228,13 @@ void UDTTest::sampleStats() {
QString::number(stats.rtt / USECS_PER_MSEC).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), QString::number(stats.rtt / USECS_PER_MSEC).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()),
QString::number(stats.congestionWindowSize).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), QString::number(stats.congestionWindowSize).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()),
QString::number(stats.packetSendPeriod).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), QString::number(stats.packetSendPeriod).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()),
QString::number(stats.receivedACKs).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), QString::number(stats.events[udt::ConnectionStats::Stats::ReceivedACK]).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()),
QString::number(stats.receivedLightACKs).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), QString::number(stats.events[udt::ConnectionStats::Stats::ProcessedACK]).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()),
QString::number(stats.receivedNAKs).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), QString::number(stats.events[udt::ConnectionStats::Stats::ReceivedLightACK]).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()),
QString::number(stats.receivedTimeoutNAKs).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), QString::number(stats.events[udt::ConnectionStats::Stats::ReceivedNAK]).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()),
QString::number(stats.sentACK2s).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), QString::number(stats.events[udt::ConnectionStats::Stats::ReceivedTimeoutNAK]).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()),
QString::number(stats.retransmissions).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()) QString::number(stats.events[udt::ConnectionStats::Stats::SentACK2]).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()),
QString::number(stats.events[udt::ConnectionStats::Stats::Retransmission]).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size())
}; };
// output this line of values // output this line of values