From 05d9845077d6991b6455f465af42a4c15ced2cf5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 28 Jul 2015 17:01:13 -0700 Subject: [PATCH] add counting of total control packets sent/received --- libraries/networking/src/udt/Connection.cpp | 34 ++++++++++++++++++-- libraries/networking/src/udt/Connection.h | 22 +++++++++++-- libraries/networking/src/udt/ControlPacket.h | 3 +- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/libraries/networking/src/udt/Connection.cpp b/libraries/networking/src/udt/Connection.cpp index cc7d1f6c09..507e11f206 100644 --- a/libraries/networking/src/udt/Connection.cpp +++ b/libraries/networking/src/udt/Connection.cpp @@ -49,14 +49,17 @@ void Connection::sync() { if (duration_cast(now - _lastNAKTime).count() >= _nakInterval) { // construct a NAK packet that will hold all of the lost sequence numbers - auto lossListPacket = ControlPacket::create(ControlPacket::NAK, _lossList.getLength() * sizeof(SequenceNumber)); - + auto lossListPacket = ControlPacket::create(ControlPacket::TimeoutNAK, _lossList.getLength() * sizeof(SequenceNumber)); + // TODO: pack in the lost sequence numbers // have our SendQueue send off this control packet _sendQueue->sendPacket(*lossListPacket); + // record this as the last NAK time _lastNAKTime = high_resolution_clock::now(); + + ++_totalSentTimeoutNAKs; } } @@ -122,9 +125,11 @@ void Connection::sendACK(bool wasCausedBySyncTimeout) { // write this ACK to the map of sent ACKs _sentACKs[_currentACKSubSequenceNumber] = { nextACKNumber, high_resolution_clock::now() }; + + ++_totalSentACKs; } -void Connection::sendLightACK() const { +void Connection::sendLightACK() { // create the light ACK packet, make it static so we can re-use it static const int LIGHT_ACK_PACKET_PAYLOAD_BYTES = sizeof(SequenceNumber); static auto lightACKPacket = ControlPacket::create(ControlPacket::ACK, LIGHT_ACK_PACKET_PAYLOAD_BYTES); @@ -144,6 +149,8 @@ void Connection::sendLightACK() const { // have the send queue send off our packet immediately _sendQueue->sendPacket(*lightACKPacket); + + ++_totalSentLightACKs; } SequenceNumber Connection::nextACK() const { @@ -190,6 +197,8 @@ void Connection::processReceivedSequenceNumber(SequenceNumber seq) { // record our last NAK time _lastNAKTime = high_resolution_clock::now(); + ++_totalSentNAKs; + // figure out when we should send the next loss report, if we haven't heard anything back _nakInterval = (_rtt + 4 * _rttVariance); @@ -212,6 +221,8 @@ void Connection::processReceivedSequenceNumber(SequenceNumber seq) { // Otherwise, it's a resend, remove it from the loss list _lossList.remove(seq); } + + ++_totalReceivedDataPackets; } void Connection::processControl(unique_ptr controlPacket) { @@ -229,6 +240,9 @@ void Connection::processControl(unique_ptr controlPacket) { case ControlPacket::NAK: processNAK(move(controlPacket)); break; + case ControlPacket::TimeoutNAK: + processTimeoutNAK(move(controlPacket)); + break; } } @@ -259,6 +273,8 @@ void Connection::processACK(std::unique_ptr controlPacket) { // update the last sent ACK2 and the last ACK2 send time _lastSentACK2 = currentACKSubSequenceNumber; lastACK2SendTime = high_resolution_clock::now(); + + ++_totalSentACK2s; } // read the ACKed sequence number @@ -330,6 +346,8 @@ void Connection::processLightACK(std::unique_ptr controlPacket) { // update the last received ACK to the this one _lastReceivedACK = ack; } + + ++_totalReceivedLightACKs; } void Connection::processACK2(std::unique_ptr controlPacket) { @@ -356,6 +374,8 @@ void Connection::processACK2(std::unique_ptr controlPacket) { _lastReceivedAcknowledgedACK = pair.first; } } + + ++_totalReceivedACK2s; } void Connection::processNAK(std::unique_ptr controlPacket) { @@ -365,6 +385,14 @@ void Connection::processNAK(std::unique_ptr controlPacket) { if (controlPacket->bytesLeftToRead() >= (qint64)sizeof(SequenceNumber)) { controlPacket->readPrimitive(&end); } + + ++_totalReceivedNAKs; +} + +void Connection::processTimeoutNAK(std::unique_ptr controlPacket) { + // read the NAKed sequence numbers from the packet + + ++_totalReceivedTimeoutNAKs; } void Connection::updateRTT(int rtt) { diff --git a/libraries/networking/src/udt/Connection.h b/libraries/networking/src/udt/Connection.h index 27057da3a9..76725cae42 100644 --- a/libraries/networking/src/udt/Connection.h +++ b/libraries/networking/src/udt/Connection.h @@ -47,12 +47,13 @@ public: private: void sendACK(bool wasCausedBySyncTimeout = true); - void sendLightACK() const; + void sendLightACK(); void processACK(std::unique_ptr controlPacket); void processLightACK(std::unique_ptr controlPacket); void processACK2(std::unique_ptr controlPacket); void processNAK(std::unique_ptr controlPacket); + void processTimeoutNAK(std::unique_ptr controlPacket); void updateRTT(int rtt); @@ -74,8 +75,6 @@ private: SequenceNumber _lastSentACK { SequenceNumber::MAX }; // The last sent ACK SequenceNumber _lastSentACK2; // The last sent ACK sub-sequence number in an ACK2 - int _totalReceivedACKs { 0 }; - int32_t _rtt; // RTT, in microseconds int32_t _rttVariance; // RTT variance int _flowWindowSize; // Flow control window size @@ -88,6 +87,23 @@ private: PacketTimeWindow _receiveWindow { 16, 64 }; // Window of interval between packets (16) and probes (64) for bandwidth and receive speed std::unique_ptr _sendQueue; + + // Control Packet stat collection + int _totalReceivedACKs { 0 }; + int _totalSentACKs { 0 }; + int _totalSentLightACKs { 0 }; + int _totalReceivedLightACKs { 0 }; + int _totalReceivedACK2s { 0 }; + int _totalSentACK2s { 0 }; + int _totalReceivedNAKs { 0 }; + int _totalSentNAKs { 0 }; + int _totalReceivedTimeoutNAKs { 0 }; + int _totalSentTimeoutNAKs { 0 }; + + // Data packet stat collection + int _totalReceivedDataPackets { 0 }; + + }; } diff --git a/libraries/networking/src/udt/ControlPacket.h b/libraries/networking/src/udt/ControlPacket.h index 4563b657a9..fdd0b65e36 100644 --- a/libraries/networking/src/udt/ControlPacket.h +++ b/libraries/networking/src/udt/ControlPacket.h @@ -29,7 +29,8 @@ public: enum Type : uint16_t { ACK, ACK2, - NAK + NAK, + TimeoutNAK }; static std::unique_ptr create(Type type, qint64 size = -1);