diff --git a/quic/api/QuicSocket.h b/quic/api/QuicSocket.h index bf5418e8e..69fc9c48b 100644 --- a/quic/api/QuicSocket.h +++ b/quic/api/QuicSocket.h @@ -142,11 +142,20 @@ class QuicSocket { uint32_t totalPacketsSpuriouslyMarkedLost{0}; uint32_t timeoutBasedLoss{0}; std::chrono::microseconds pto{0us}; + // // Number of Bytes (packet header + body) that were sent uint64_t bytesSent{0}; + // // Number of Bytes (packet header + body) that were acked uint64_t bytesAcked{0}; + // // Number of Bytes (packet header + body) that were received uint64_t bytesRecvd{0}; + // // Number of Bytes (packet header + body) that are in-flight uint64_t bytesInFlight{0}; + // // Number of Bytes (packet header + body) that were retxed uint64_t totalBytesRetransmitted{0}; + // Number of Bytes (only the encoded packet's body) that were sent + uint64_t bodyBytesSent{0}; + // Number of Bytes (only the encoded packet's body) that were acked + uint64_t bodyBytesAcked{0}; uint32_t ptoCount{0}; uint32_t totalPTOCount{0}; folly::Optional largestPacketAckedByPeer; diff --git a/quic/api/QuicTransportBase.cpp b/quic/api/QuicTransportBase.cpp index 63e50ccbb..2024dd184 100644 --- a/quic/api/QuicTransportBase.cpp +++ b/quic/api/QuicTransportBase.cpp @@ -603,6 +603,9 @@ QuicSocket::TransportInfo QuicTransportBase::getTransportInfo() const { transportInfo.bytesAcked = conn_->lossState.totalBytesAcked; transportInfo.bytesRecvd = conn_->lossState.totalBytesRecvd; transportInfo.bytesInFlight = conn_->lossState.inflightBytes; + transportInfo.bodyBytesSent = conn_->lossState.totalBodyBytesSent; + transportInfo.bodyBytesAcked = conn_->lossState.totalBodyBytesAcked; + transportInfo.ptoCount = conn_->lossState.ptoCount; transportInfo.totalPTOCount = conn_->lossState.totalPTOCount; transportInfo.largestPacketAckedByPeer = diff --git a/quic/api/QuicTransportFunctions.cpp b/quic/api/QuicTransportFunctions.cpp index b8358a20d..ed8cc6d83 100644 --- a/quic/api/QuicTransportFunctions.cpp +++ b/quic/api/QuicTransportFunctions.cpp @@ -261,6 +261,7 @@ DataPathResult continuousMemoryBuildScheduleEncrypt( headerCipher); CHECK(!packetBuf->isChained()); auto encodedSize = packetBuf->length(); + auto encodedBodySize = encodedSize - headerLen; // Include previous packets back. packetBuf->prepend(prevSize); connection.bufAccessor->release(std::move(packetBuf)); @@ -280,7 +281,8 @@ DataPathResult continuousMemoryBuildScheduleEncrypt( QUIC_STATS(connection.statsCallback, onWrite, encodedSize); QUIC_STATS(connection.statsCallback, onPacketSent); } - return DataPathResult::makeWriteResult(ret, std::move(result), encodedSize); + return DataPathResult::makeWriteResult( + ret, std::move(result), encodedSize, encodedBodySize); } DataPathResult iobufChainBasedBuildScheduleEncrypt( @@ -344,10 +346,12 @@ DataPathResult iobufChainBasedBuildScheduleEncrypt( packetBuf->length() - headerLen, headerCipher); auto encodedSize = packetBuf->computeChainDataLength(); + auto encodedBodySize = encodedSize - headerLen; #if !FOLLY_MOBILE if (encodedSize > connection.udpSendPacketLen) { LOG_EVERY_N(ERROR, 5000) - << "Quic sending pkt larger than limit, encodedSize=" << encodedSize; + << "Quic sending pkt larger than limit, encodedSize=" << encodedSize + << " encodedBodySize=" << encodedBodySize; } #endif bool ret = ioBufBatch.write(std::move(packetBuf), encodedSize); @@ -356,7 +360,8 @@ DataPathResult iobufChainBasedBuildScheduleEncrypt( QUIC_STATS(connection.statsCallback, onWrite, encodedSize); QUIC_STATS(connection.statsCallback, onPacketSent); } - return DataPathResult::makeWriteResult(ret, std::move(result), encodedSize); + return DataPathResult::makeWriteResult( + ret, std::move(result), encodedSize, encodedBodySize); } } // namespace @@ -561,6 +566,7 @@ void updateConnection( RegularQuicWritePacket packet, TimePoint sentTime, uint32_t encodedSize, + uint32_t encodedBodySize, bool isDSRPacket) { auto packetNum = packet.header.getPacketSequenceNum(); bool retransmittable = false; // AckFrame and PaddingFrame are not retx-able. @@ -574,7 +580,7 @@ void updateConnection( conn.d6d.lastProbe->packetNum == packetNum; VLOG(10) << nodeToString(conn.nodeType) << " sent packetNum=" << packetNum << " in space=" << packetNumberSpace << " size=" << encodedSize - << " " << conn; + << " bodySize: " << encodedBodySize << " " << conn; if (conn.qLogger) { conn.qLogger->addPacket(packet, encodedSize); } @@ -749,6 +755,7 @@ void updateConnection( conn.pendingEvents.setLossDetectionAlarm = retransmittable; } conn.lossState.totalBytesSent += encodedSize; + conn.lossState.totalBodyBytesSent += encodedBodySize; conn.lossState.totalPacketsSent++; if (!retransmittable && !isPing) { @@ -771,12 +778,14 @@ void updateConnection( std::move(packet), sentTime, encodedSize, + encodedBodySize, isHandshake, isD6DProbe, // these numbers should all _include_ the current packet // conn.lossState.inflightBytes isn't updated until below // conn.outstandings.numOutstanding() + 1 since we're emplacing here conn.lossState.totalBytesSent, + conn.lossState.totalBodyBytesSent, conn.lossState.inflightBytes + encodedSize, conn.outstandings.numOutstanding() + 1, conn.lossState, @@ -1349,6 +1358,7 @@ uint64_t writeConnectionDataToSocket( std::move(result->packet->packet), Clock::now(), folly::to(ret.encodedSize), + folly::to(ret.encodedBodySize), false /* isDSRPacket */); // if ioBufBatch.write returns false diff --git a/quic/api/QuicTransportFunctions.h b/quic/api/QuicTransportFunctions.h index 934ca644c..208502270 100644 --- a/quic/api/QuicTransportFunctions.h +++ b/quic/api/QuicTransportFunctions.h @@ -26,6 +26,7 @@ struct DataPathResult { bool writeSuccess{false}; folly::Optional result; uint64_t encodedSize{0}; + uint64_t encodedBodySize{0}; static DataPathResult makeBuildFailure() { return DataPathResult(); @@ -34,8 +35,10 @@ struct DataPathResult { static DataPathResult makeWriteResult( bool writeSuc, SchedulingResult&& res, - uint64_t encodedSizeIn) { - return DataPathResult(writeSuc, std::move(res), encodedSizeIn); + uint64_t encodedSizeIn, + uint64_t encodedBodySizeIn) { + return DataPathResult( + writeSuc, std::move(res), encodedSizeIn, encodedBodySizeIn); } private: @@ -44,11 +47,13 @@ struct DataPathResult { explicit DataPathResult( bool writeSuc, SchedulingResult&& res, - uint64_t encodedSizeIn) + uint64_t encodedSizeIn, + uint64_t encodedBodySizeIn) : buildSuccess(true), writeSuccess(writeSuc), result(std::move(res)), - encodedSize(encodedSizeIn) {} + encodedSize(encodedSizeIn), + encodedBodySize(encodedBodySizeIn) {} }; using DataPathFunc = std::functionpacket, Clock::now(), bufferLength, + 0, false /* isDSRPacket */); buf = bufAccessor.obtain(); ASSERT_EQ(conn.udpSendPacketLen, buf->length()); @@ -960,6 +961,7 @@ TEST_F(QuicPacketSchedulerTest, CloneLargerThanOriginalPacket) { packetResult.packet->packet, Clock::now(), encodedSize, + 0, false /* isDSRPacket */); // make packetNum too larger to be encoded into the same size: @@ -1581,7 +1583,7 @@ TEST_F(QuicPacketSchedulerTest, WriteLossWithoutFlowControl) { scheduler.writeStreams(builder1); auto packet1 = std::move(builder1).buildPacket().packet; updateConnection( - conn, folly::none, packet1, Clock::now(), 1000, false /* isDSR */); + conn, folly::none, packet1, Clock::now(), 1000, 0, false /* isDSR */); EXPECT_EQ(1, packet1.frames.size()); auto& writeStreamFrame1 = *packet1.frames[0].asWriteStreamFrame(); EXPECT_EQ(streamId, writeStreamFrame1.streamId); @@ -1608,7 +1610,7 @@ TEST_F(QuicPacketSchedulerTest, WriteLossWithoutFlowControl) { scheduler.writeStreams(builder2); auto packet2 = std::move(builder2).buildPacket().packet; updateConnection( - conn, folly::none, packet2, Clock::now(), 1000, false /* isDSR */); + conn, folly::none, packet2, Clock::now(), 1000, 0, false /* isDSR */); EXPECT_EQ(1, packet2.frames.size()); auto& writeStreamFrame2 = *packet2.frames[0].asWriteStreamFrame(); EXPECT_EQ(streamId, writeStreamFrame2.streamId); @@ -1653,7 +1655,7 @@ TEST_F(QuicPacketSchedulerTest, RunOutFlowControlDuringStreamWrite) { scheduler.writeStreams(builder1); auto packet1 = std::move(builder1).buildPacket().packet; updateConnection( - conn, folly::none, packet1, Clock::now(), 1200, false /* isDSR */); + conn, folly::none, packet1, Clock::now(), 1200, 0, false /* isDSR */); EXPECT_EQ(2, packet1.frames.size()); auto& writeStreamFrame1 = *packet1.frames[0].asWriteStreamFrame(); EXPECT_EQ(streamId1, writeStreamFrame1.streamId); diff --git a/quic/api/test/QuicTransportFunctionsTest.cpp b/quic/api/test/QuicTransportFunctionsTest.cpp index 6e4f286d7..57712600f 100644 --- a/quic/api/test/QuicTransportFunctionsTest.cpp +++ b/quic/api/test/QuicTransportFunctionsTest.cpp @@ -141,6 +141,15 @@ uint64_t getEncodedSize(const RegularQuicPacketBuilder::Packet& packet) { return encodedSize; } +uint64_t getEncodedBodySize(const RegularQuicPacketBuilder::Packet& packet) { + // calculate size as the plaintext size + uint32_t encodedBodySize = 0; + if (packet.body) { + encodedBodySize += packet.body->computeChainDataLength(); + } + return encodedBodySize; +} + class QuicTransportFunctionsTest : public Test { public: void SetUp() override { @@ -193,6 +202,7 @@ TEST_F(QuicTransportFunctionsTest, PingPacketGoesToOPList) { packet.packet, Clock::now(), 50, + 0, false /* isDSRPacket */); EXPECT_EQ(1, conn->outstandings.packets.size()); // But it won't set loss detection alarm @@ -242,6 +252,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnection) { packet.packet, TimePoint{}, getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); EXPECT_EQ( @@ -305,6 +316,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnection) { packet2.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); EXPECT_EQ( conn->ackStates.initialAckState.nextPacketNum, @@ -387,6 +399,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionD6DNotConsumeSendPing) { packet.packet, Clock::now(), 50, + 0, false /* isDSRPacket */); EXPECT_EQ(1, conn->outstandings.packets.size()); EXPECT_TRUE(conn->outstandings.packets.front().metadata.isD6DProbe); @@ -408,6 +421,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionD6DNeedsAppDataPNSpace) { packet.packet, Clock::now(), 50, + 0, false /* isDSRPacket */); EXPECT_EQ(1, conn->outstandings.packets.size()); EXPECT_FALSE(conn->outstandings.packets.front().metadata.isD6DProbe); @@ -440,6 +454,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionPacketSorting) { handshakePacket.packet, TimePoint{}, getEncodedSize(handshakePacket), + getEncodedBodySize(handshakePacket), false /* isDSRPacket */); updateConnection( *conn, @@ -447,6 +462,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionPacketSorting) { initialPacket.packet, TimePoint{}, getEncodedSize(initialPacket), + getEncodedBodySize(initialPacket), false /* isDSRPacket */); updateConnection( *conn, @@ -454,6 +470,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionPacketSorting) { appDataPacket.packet, TimePoint{}, getEncodedSize(appDataPacket), + getEncodedBodySize(appDataPacket), false /* isDSRPacket */); // verify qLogger added correct logs std::shared_ptr qLogger = @@ -505,6 +522,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionFinOnly) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); // verify QLogger contains correct packet information @@ -555,6 +573,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionAllBytesExceptFin) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); // verify QLogger contains correct packet information @@ -604,6 +623,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionEmptyAckWriteResult) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); // verify QLogger contains correct packet information @@ -644,6 +664,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionPureAckCounter) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); auto nonHandshake = buildEmptyPacket(*conn, PacketNumberSpace::Handshake); @@ -666,6 +687,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionPureAckCounter) { packet2.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); // verify QLogger contains correct packet and frame information @@ -701,6 +723,7 @@ TEST_F(QuicTransportFunctionsTest, TestPaddingPureAckPacketIsStillPureAck) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); // verify QLogger contains correct packet and frames information @@ -737,6 +760,7 @@ TEST_F(QuicTransportFunctionsTest, TestImplicitAck) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); EXPECT_EQ(1, conn->outstandings.initialPacketsCount); EXPECT_EQ(0, conn->outstandings.handshakePacketsCount); @@ -756,6 +780,7 @@ TEST_F(QuicTransportFunctionsTest, TestImplicitAck) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); EXPECT_EQ(2, conn->outstandings.initialPacketsCount); EXPECT_EQ(0, conn->outstandings.handshakePacketsCount); @@ -786,6 +811,7 @@ TEST_F(QuicTransportFunctionsTest, TestImplicitAck) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); EXPECT_EQ(1, conn->outstandings.initialPacketsCount); EXPECT_EQ(1, conn->outstandings.handshakePacketsCount); @@ -802,6 +828,7 @@ TEST_F(QuicTransportFunctionsTest, TestImplicitAck) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); EXPECT_EQ(1, conn->outstandings.initialPacketsCount); EXPECT_EQ(2, conn->outstandings.handshakePacketsCount); @@ -858,6 +885,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionHandshakeCounter) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); EXPECT_EQ(1, conn->outstandings.handshakePacketsCount); @@ -877,6 +905,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionHandshakeCounter) { nonHandshake.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); // verify QLogger contains correct packet information @@ -932,6 +961,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionForOneRttCryptoData) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); EXPECT_EQ(0, conn->outstandings.handshakePacketsCount); @@ -953,6 +983,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionForOneRttCryptoData) { nonHandshake.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); // verify QLogger contains correct packet information @@ -1016,6 +1047,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionWithPureAck) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); EXPECT_EQ(1, conn->lossState.totalPacketsSent); EXPECT_EQ(0, conn->lossState.totalAckElicitingPacketsSent); @@ -1049,7 +1081,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionWithBytesStats) { WriteStreamFrame writeStreamFrame(stream->id, 0, 5, false); packet.packet.frames.push_back(std::move(writeStreamFrame)); conn->lossState.totalBytesSent = 13579; - conn->lossState.totalBytesAcked = 8642; + conn->lossState.totalBodyBytesSent = 13000; conn->lossState.inflightBytes = 16000; auto currentTime = Clock::now(); conn->lossState.lastAckedTime = currentTime - 123s; @@ -1065,6 +1097,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionWithBytesStats) { packet.packet, TimePoint(), 555, + 500, false /* isDSRPacket */); EXPECT_EQ(21, conn->lossState.totalPacketsSent); EXPECT_EQ(16, conn->lossState.totalAckElicitingPacketsSent); @@ -1086,6 +1119,10 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionWithBytesStats) { 13579 + 555, getFirstOutstandingPacket(*conn, PacketNumberSpace::Handshake) ->metadata.totalBytesSent); + EXPECT_EQ( + 13000 + 500, + getFirstOutstandingPacket(*conn, PacketNumberSpace::Handshake) + ->metadata.totalBodyBytesSent); EXPECT_EQ( 16000 + 555, getFirstOutstandingPacket(*conn, PacketNumberSpace::Handshake) @@ -1098,6 +1135,10 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionWithBytesStats) { 555, getFirstOutstandingPacket(*conn, PacketNumberSpace::Handshake) ->metadata.encodedSize); + EXPECT_EQ( + 500, + getFirstOutstandingPacket(*conn, PacketNumberSpace::Handshake) + ->metadata.encodedBodySize); EXPECT_EQ( 20 + 1, getFirstOutstandingPacket(*conn, PacketNumberSpace::Handshake) @@ -1157,6 +1198,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionWithCloneResult) { std::move(writePacket), MockClock::now(), 1500, + 1400, false /* isDSRPacket */); // verify QLogger contains correct packet information std::shared_ptr qLogger = @@ -1183,6 +1225,10 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionWithCloneResult) { 1500, getLastOutstandingPacket(*conn, PacketNumberSpace::AppData) ->metadata.encodedSize); + EXPECT_EQ( + 1400, + getLastOutstandingPacket(*conn, PacketNumberSpace::AppData) + ->metadata.encodedBodySize); EXPECT_EQ( event, *getLastOutstandingPacket(*conn, PacketNumberSpace::AppData) @@ -1204,6 +1250,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionStreamWindowUpdate) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); // verify QLogger contains correct packet information @@ -1239,6 +1286,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionConnWindowUpdate) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); // verify QLogger contains correct packet information @@ -2191,6 +2239,7 @@ TEST_F(QuicTransportFunctionsTest, UpdateConnectionCloneCounter) { packet.packet, TimePoint(), 123, + 100, false /* isDSRPacket */); EXPECT_EQ(1, conn->outstandings.clonedPacketsCount); } @@ -2208,6 +2257,7 @@ TEST_F(QuicTransportFunctionsTest, ClearBlockedFromPendingEvents) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); EXPECT_FALSE(conn->streamManager->hasBlocked()); EXPECT_FALSE(conn->outstandings.packets.empty()); @@ -2231,6 +2281,7 @@ TEST_F(QuicTransportFunctionsTest, ClonedBlocked) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); EXPECT_FALSE(conn->outstandings.packets.empty()); EXPECT_EQ(1, conn->outstandings.clonedPacketsCount); @@ -2251,6 +2302,7 @@ TEST_F(QuicTransportFunctionsTest, TwoConnWindowUpdateWillCrash) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */), ".*Send more than one connection window update.*"); } @@ -2269,6 +2321,7 @@ TEST_F(QuicTransportFunctionsTest, WriteStreamFrameIsNotPureAck) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); EXPECT_FALSE(conn->outstandings.packets.empty()); } @@ -2287,6 +2340,7 @@ TEST_F(QuicTransportFunctionsTest, ClearRstFromPendingEvents) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); EXPECT_TRUE(conn->pendingEvents.resets.empty()); EXPECT_FALSE(conn->outstandings.packets.empty()); @@ -2311,6 +2365,7 @@ TEST_F(QuicTransportFunctionsTest, ClonedRst) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), false /* isDSRPacket */); EXPECT_FALSE(conn->outstandings.packets.empty()); EXPECT_EQ(1, conn->outstandings.clonedPacketsCount); @@ -2319,6 +2374,7 @@ TEST_F(QuicTransportFunctionsTest, ClonedRst) { TEST_F(QuicTransportFunctionsTest, TotalBytesSentUpdate) { auto conn = createConn(); conn->lossState.totalBytesSent = 1234; + conn->lossState.totalBodyBytesSent = 1000; auto packet = buildEmptyPacket(*conn, PacketNumberSpace::Handshake); updateConnection( *conn, @@ -2326,8 +2382,10 @@ TEST_F(QuicTransportFunctionsTest, TotalBytesSentUpdate) { packet.packet, TimePoint{}, 4321, + 4000, false /* isDSRPacket */); EXPECT_EQ(5555, conn->lossState.totalBytesSent); + EXPECT_EQ(5000, conn->lossState.totalBodyBytesSent); } TEST_F(QuicTransportFunctionsTest, TotalPacketsSentUpdate) { @@ -2341,6 +2399,7 @@ TEST_F(QuicTransportFunctionsTest, TotalPacketsSentUpdate) { packet.packet, TimePoint{}, 4321, + 0, false /* isDSRPacket */); EXPECT_EQ(startTotalPacketsSent + 1, conn->lossState.totalPacketsSent); } @@ -2360,7 +2419,8 @@ TEST_F(QuicTransportFunctionsTest, TimeoutBasedRetxCountUpdate) { packetEvent, packet.packet, TimePoint(), - 500, + 0, + 0, false /* isDSRPacket */); EXPECT_EQ(247, conn->lossState.timeoutBasedRtxCount); } @@ -2808,6 +2868,7 @@ TEST_F(QuicTransportFunctionsTest, UpdateConnectionWithBufferMeta) { packet.packet, TimePoint(), getEncodedSize(packet), + getEncodedBodySize(packet), true /* dsr */); EXPECT_EQ(1000 + bufMetaStartingOffset, stream->writeBufMeta.offset); EXPECT_EQ(1000, stream->writeBufMeta.length); @@ -2836,6 +2897,7 @@ TEST_F(QuicTransportFunctionsTest, UpdateConnectionWithBufferMeta) { retxPacket.packet, TimePoint(), getEncodedSize(retxPacket), + getEncodedBodySize(packet), true /* dsr */); EXPECT_TRUE(stream->lossBufMetas.empty()); retxBufMetaIter = stream->retransmissionBufMetas.find(bufMetaStartingOffset); diff --git a/quic/codec/test/QuicPacketRebuilderTest.cpp b/quic/codec/test/QuicPacketRebuilderTest.cpp index 66a6a5b5b..0d7666a1d 100644 --- a/quic/codec/test/QuicPacketRebuilderTest.cpp +++ b/quic/codec/test/QuicPacketRebuilderTest.cpp @@ -32,10 +32,12 @@ OutstandingPacket makeDummyOutstandingPacket( writePacket, Clock::now(), 1000, + 0, false, totalBytesSentOnConnection, 0, 0, + 0, LossState()); return packet; } diff --git a/quic/common/test/TestUtils.cpp b/quic/common/test/TestUtils.cpp index f0768cf57..0b155c490 100644 --- a/quic/common/test/TestUtils.cpp +++ b/quic/common/test/TestUtils.cpp @@ -577,8 +577,10 @@ OutstandingPacket makeTestingWritePacket( packet, sentTime, desiredSize, + 0, false, totalBytesSent, + 0, inflightBytes, 0, LossState(), diff --git a/quic/congestion_control/test/CopaTest.cpp b/quic/congestion_control/test/CopaTest.cpp index 50b4a0617..1873c4a59 100644 --- a/quic/congestion_control/test/CopaTest.cpp +++ b/quic/congestion_control/test/CopaTest.cpp @@ -34,10 +34,12 @@ class CopaTest : public Test { std::move(packet), Clock::now(), 10, + 0, false, totalSentBytes, 0, 0, + 0, LossState())); loss.lostBytes = packetData.second; } @@ -57,8 +59,10 @@ class CopaTest : public Test { std::move(packet), Clock::now(), size, + 0, false, totalSent, + 0, inflight, 0, LossState()); diff --git a/quic/congestion_control/test/NewRenoTest.cpp b/quic/congestion_control/test/NewRenoTest.cpp index ee05ac48a..770221822 100644 --- a/quic/congestion_control/test/NewRenoTest.cpp +++ b/quic/congestion_control/test/NewRenoTest.cpp @@ -27,7 +27,16 @@ CongestionController::LossEvent createLossEvent( RegularQuicWritePacket packet( ShortHeader(ProtectionType::KeyPhaseZero, connId, packetData.first)); loss.addLostPacket(OutstandingPacket( - std::move(packet), Clock::now(), 10, false, 10, 0, 0, LossState())); + std::move(packet), + Clock::now(), + 10, + 0, + false, + 10, + 0, + 0, + 0, + LossState())); loss.lostBytes = packetData.second; } loss.lostPackets = lostPackets.size(); @@ -49,10 +58,12 @@ CongestionController::AckEvent createAckEvent( std::move(packet), packetSentTime, ackedSize, + 0, false, ackedSize, 0, 0, + 0, LossState()))); return ack; } @@ -66,7 +77,16 @@ OutstandingPacket createPacket( RegularQuicWritePacket packet( ShortHeader(ProtectionType::KeyPhaseZero, connId, packetNum)); return OutstandingPacket( - std::move(packet), sendTime, size, false, size, inflight, 0, LossState()); + std::move(packet), + sendTime, + size, + 0, + false, + size, + 0, + inflight, + 0, + LossState()); } TEST_F(NewRenoTest, TestLoss) { diff --git a/quic/d6d/test/QuicD6DStateFunctionsTest.cpp b/quic/d6d/test/QuicD6DStateFunctionsTest.cpp index 1cbc81dd1..77dc2fc9a 100644 --- a/quic/d6d/test/QuicD6DStateFunctionsTest.cpp +++ b/quic/d6d/test/QuicD6DStateFunctionsTest.cpp @@ -206,6 +206,7 @@ TEST_F(QuicD6DStateFunctionsTest, D6DProbeAckedInBase) { makeTestShortPacket(), Clock::now(), d6d.currentProbeSize, + 0, false, true, d6d.currentProbeSize, @@ -252,6 +253,7 @@ TEST_F(QuicD6DStateFunctionsTest, D6DProbeAckedInSearchingOne) { makeTestShortPacket(), Clock::now(), d6d.currentProbeSize, + 0, false, true, d6d.currentProbeSize, @@ -299,6 +301,7 @@ TEST_F(QuicD6DStateFunctionsTest, D6DProbeAckedInSearchingMax) { makeTestShortPacket(), Clock::now(), d6d.currentProbeSize, + 0, false, true, d6d.currentProbeSize, @@ -354,6 +357,7 @@ TEST_F(QuicD6DStateFunctionsTest, D6DProbeAckedInError) { makeTestShortPacket(), Clock::now(), d6d.currentProbeSize, + 0, false, true, d6d.currentProbeSize, @@ -399,6 +403,7 @@ TEST_F(QuicD6DStateFunctionsTest, BlackholeInSearching) { makeTestShortPacket(), now + 10s, d6d.currentProbeSize, + 0, false, true, d6d.currentProbeSize, @@ -412,8 +417,10 @@ TEST_F(QuicD6DStateFunctionsTest, BlackholeInSearching) { makeTestShortPacket(), now + 8s, conn.udpSendPacketLen, + 0, false, conn.udpSendPacketLen + d6d.currentProbeSize, + 0, conn.udpSendPacketLen + d6d.currentProbeSize, 0, LossState()); @@ -468,6 +475,7 @@ TEST_F(QuicD6DStateFunctionsTest, BlackholeInSearchComplete) { makeTestShortPacket(), now + 10s, d6d.currentProbeSize, + 0, false, true, d6d.currentProbeSize, @@ -481,8 +489,10 @@ TEST_F(QuicD6DStateFunctionsTest, BlackholeInSearchComplete) { makeTestShortPacket(), now + 12s, conn.udpSendPacketLen, + 0, false, conn.udpSendPacketLen + d6d.currentProbeSize, + 0, conn.udpSendPacketLen + d6d.currentProbeSize, 0, LossState()); @@ -540,6 +550,7 @@ TEST_F(QuicD6DStateFunctionsTest, ReachMaxPMTU) { makeTestShortPacket(), Clock::now(), d6d.currentProbeSize, + 0, false, true, d6d.currentProbeSize, @@ -579,6 +590,7 @@ TEST_F( makeTestShortPacket(), Clock::now(), d6d.currentProbeSize, + 0, false, true, d6d.currentProbeSize, @@ -600,6 +612,7 @@ TEST_F( makeTestShortPacket(), Clock::now(), d6d.currentProbeSize, + 0, false, false, d6d.currentProbeSize, @@ -638,6 +651,7 @@ TEST_F(QuicD6DStateFunctionsTest, UpperboundIsBase) { makeTestShortPacket(), Clock::now(), d6d.currentProbeSize, + 0, false, true, d6d.currentProbeSize, diff --git a/quic/dsr/WriteFunctions.cpp b/quic/dsr/WriteFunctions.cpp index 58422ada4..b2ba4cc82 100644 --- a/quic/dsr/WriteFunctions.cpp +++ b/quic/dsr/WriteFunctions.cpp @@ -73,6 +73,10 @@ uint64_t writePacketizationRequest( packet.packet, Clock::now(), packet.encodedSize, + // TODO: (yangchi) Figure out how to calculate the + // packet.encodedBodySize for the DSR case. For now, it's not being + // used, so setting it to 0 + 0, true /* isDSRPacket */); if (!instructionAdded) { diff --git a/quic/loss/test/QuicLossFunctionsTest.cpp b/quic/loss/test/QuicLossFunctionsTest.cpp index 429d64a5c..60751a857 100644 --- a/quic/loss/test/QuicLossFunctionsTest.cpp +++ b/quic/loss/test/QuicLossFunctionsTest.cpp @@ -236,19 +236,23 @@ PacketNum QuicLossFunctionsTest::sendPacket( packet = std::move(sizeEnforcedBuilder).buildPacket(); } uint32_t encodedSize = 0; + uint32_t encodedBodySize = 0; if (packet.header) { encodedSize += packet.header->computeChainDataLength(); } if (packet.body) { encodedSize += packet.body->computeChainDataLength(); + encodedBodySize += packet.body->computeChainDataLength(); } auto outstandingPacket = OutstandingPacket( packet.packet, time, encodedSize, + encodedBodySize, isHandshake, isD6DProbe, encodedSize, + encodedBodySize, 0, 0, LossState()); @@ -1069,7 +1073,7 @@ TEST_F(QuicLossFunctionsTest, TestHandleAckForLoss) { RegularQuicWritePacket outstandingRegularPacket(std::move(longHeader)); auto now = Clock::now(); conn->outstandings.packets.emplace_back(OutstandingPacket( - outstandingRegularPacket, now, 0, false, 0, 0, 0, LossState())); + outstandingRegularPacket, now, 0, 0, false, 0, 0, 0, 0, LossState())); bool testLossMarkFuncCalled = false; auto testLossMarkFunc = [&](auto& /* conn */, auto&, bool) { diff --git a/quic/state/AckHandlers.cpp b/quic/state/AckHandlers.cpp index 6899cdbf8..0d6a49d5f 100644 --- a/quic/state/AckHandlers.cpp +++ b/quic/state/AckHandlers.cpp @@ -200,6 +200,8 @@ void processAckFrame( conn.lossState.totalBytesSentAtLastAck = conn.lossState.totalBytesSent; conn.lossState.totalBytesAckedAtLastAck = conn.lossState.totalBytesAcked; + conn.lossState.totalBodyBytesAcked += + rPacketIt->metadata.encodedBodySize; if (!lastAckedPacketSentTime) { lastAckedPacketSentTime = rPacketIt->metadata.time; } diff --git a/quic/state/LossState.h b/quic/state/LossState.h index fa632c84f..2bbc35f2a 100644 --- a/quic/state/LossState.h +++ b/quic/state/LossState.h @@ -58,6 +58,14 @@ struct LossState { // The total number of bytes acked on this connection when the last time a // packet is acked. uint64_t totalBytesAckedAtLastAck{0}; + + // Total number of body bytes sent on this connection. This is after encoding. + uint64_t totalBodyBytesSent{0}; + // Total number of body bytes acked on this connection. If a packet is acked + // twice, it won't be count twice. Pure acks packets are NOT included (as they + // have no encoded body bytes). + uint64_t totalBodyBytesAcked{0}; + // Total number of packets sent on this connection, including retransmissions. uint32_t totalPacketsSent{0}; // Total number of ack-eliciting packets sent on this connection. diff --git a/quic/state/OutstandingPacket.h b/quic/state/OutstandingPacket.h index 7fd0b2f06..4952f8bc6 100644 --- a/quic/state/OutstandingPacket.h +++ b/quic/state/OutstandingPacket.h @@ -19,6 +19,8 @@ struct OutstandingPacketMetadata { TimePoint time; // Size of the packet sent on the wire. uint32_t encodedSize; + // Size of only the body within the packet sent on the wire. + uint32_t encodedBodySize; // Whether this packet has any data from stream 0 bool isHandshake; // Whether the packet is a d6d probe @@ -26,6 +28,9 @@ struct OutstandingPacketMetadata { // Total sent bytes on this connection including this packet itself when this // packet is sent. uint64_t totalBytesSent; + // Total sent body bytes on this connection including this packet itself when + // this packet is sent. + uint64_t totalBodyBytesSent; // Bytes in flight on this connection including this packet itself when this // packet is sent. uint64_t inflightBytes; @@ -42,18 +47,22 @@ struct OutstandingPacketMetadata { OutstandingPacketMetadata( TimePoint timeIn, uint32_t encodedSizeIn, + uint32_t encodedBodySizeIn, bool isHandshakeIn, bool isD6DProbeIn, uint64_t totalBytesSentIn, + uint64_t totalBodyBytesSentIn, uint64_t inflightBytesIn, uint64_t packetsInflightIn, const LossState& lossStateIn, uint64_t writeCount) : time(timeIn), encodedSize(encodedSizeIn), + encodedBodySize(encodedBodySizeIn), isHandshake(isHandshakeIn), isD6DProbe(isD6DProbeIn), totalBytesSent(totalBytesSentIn), + totalBodyBytesSent(totalBodyBytesSentIn), inflightBytes(inflightBytesIn), packetsInflight(packetsInflightIn), totalPacketsSent(lossStateIn.totalPacketsSent), @@ -80,7 +89,6 @@ struct OutstandingPacket { // Total acked bytes on this connection when last acked packet is acked, // including the last acked packet. uint64_t totalBytesAcked; - LastAckedPacketInfo( TimePoint sentTimeIn, TimePoint ackTimeIn, @@ -123,8 +131,10 @@ struct OutstandingPacket { RegularQuicWritePacket packetIn, TimePoint timeIn, uint32_t encodedSizeIn, + uint32_t encodedBodySizeIn, bool isHandshakeIn, uint64_t totalBytesSentIn, + uint64_t totalBodyBytesSentIn, uint64_t inflightBytesIn, uint64_t packetsInflightIn, const LossState& lossStateIn, @@ -133,9 +143,11 @@ struct OutstandingPacket { metadata(OutstandingPacketMetadata( timeIn, encodedSizeIn, + encodedBodySizeIn, isHandshakeIn, false, totalBytesSentIn, + totalBodyBytesSentIn, inflightBytesIn, packetsInflightIn, lossStateIn, @@ -145,9 +157,11 @@ struct OutstandingPacket { RegularQuicWritePacket packetIn, TimePoint timeIn, uint32_t encodedSizeIn, + uint32_t encodedBodySizeIn, bool isHandshakeIn, bool isD6DProbeIn, uint64_t totalBytesSentIn, + uint64_t totalBodyBytesSentIn, uint64_t inflightBytesIn, uint64_t packetsInflightIn, const LossState& lossStateIn, @@ -156,9 +170,11 @@ struct OutstandingPacket { metadata(OutstandingPacketMetadata( timeIn, encodedSizeIn, + encodedBodySizeIn, isHandshakeIn, isD6DProbeIn, totalBytesSentIn, + totalBodyBytesSentIn, inflightBytesIn, packetsInflightIn, lossStateIn, diff --git a/quic/state/test/AckHandlersTest.cpp b/quic/state/test/AckHandlersTest.cpp index 370a1a0a8..713ab9343 100644 --- a/quic/state/test/AckHandlersTest.cpp +++ b/quic/state/test/AckHandlersTest.cpp @@ -55,8 +55,10 @@ auto emplacePackets( std::move(regularPacket), sentTime, 1, + 0, false /* handshake */, packetNum, + 0, packetNum + 1, packetNum + 1, quic::LossState()); @@ -86,10 +88,12 @@ TEST_P(AckHandlersTest, TestAckMultipleSequentialBlocks) { std::move(regularPacket), sentTime, 1, + 0, false, packetNum, 0, 0, + 0, LossState())); } ReadAckFrame ackFrame; @@ -164,10 +168,12 @@ TEST_P(AckHandlersTest, TestAckMultipleSequentialBlocksLoss) { std::move(regularPacket), sentTime, 1, + 0, false, packetNum, 0, 0, + 0, LossState())); } ReadAckFrame ackFrame; @@ -306,10 +312,12 @@ TEST_P(AckHandlersTest, TestAckBlocksWithGaps) { std::move(regularPacket), Clock::now(), 1, + 0, false, packetNum, 0, 0, + 0, LossState())); } @@ -411,10 +419,12 @@ TEST_P(AckHandlersTest, TestNonSequentialPacketNumbers) { std::move(regularPacket), Clock::now(), 1, + 0, false, packetNum, 0, 0, + 0, LossState())); } @@ -427,10 +437,12 @@ TEST_P(AckHandlersTest, TestNonSequentialPacketNumbers) { std::move(regularPacket), Clock::now(), 1, + 0, false, packetNum, 0, 0, + 0, LossState())); } @@ -512,7 +524,16 @@ TEST_P(AckHandlersTest, AckVisitorForAckTest) { conn.ackStates.appDataAckState.acks.insert(500, 700); firstPacket.frames.emplace_back(std::move(firstAckFrame)); conn.outstandings.packets.emplace_back(OutstandingPacket( - std::move(firstPacket), Clock::now(), 0, false, 0, 0, 0, LossState())); + std::move(firstPacket), + Clock::now(), + 0, + 0, + false, + 0, + 0, + 0, + 0, + LossState())); auto secondPacket = createNewPacket(101 /* packetNum */, GetParam()); WriteAckFrame secondAckFrame; @@ -522,7 +543,16 @@ TEST_P(AckHandlersTest, AckVisitorForAckTest) { conn.ackStates.appDataAckState.acks.insert(1002, 1090); secondPacket.frames.emplace_back(std::move(secondAckFrame)); conn.outstandings.packets.emplace_back(OutstandingPacket( - std::move(secondPacket), Clock::now(), 0, false, 0, 0, 0, LossState())); + std::move(secondPacket), + Clock::now(), + 0, + 0, + false, + 0, + 0, + 0, + 0, + LossState())); ReadAckFrame firstReceivedAck; firstReceivedAck.largestAcked = 100; @@ -583,7 +613,16 @@ TEST_P(AckHandlersTest, NoNewAckedPacket) { PacketNum packetAfterRtoNum = 10; auto packetAfterRto = createNewPacket(packetAfterRtoNum, GetParam()); conn.outstandings.packets.emplace_back(OutstandingPacket( - std::move(packetAfterRto), Clock::now(), 0, false, 0, 0, 0, LossState())); + std::move(packetAfterRto), + Clock::now(), + 0, + 0, + false, + 0, + 0, + 0, + 0, + LossState())); ReadAckFrame ackFrame; ackFrame.largestAcked = 5; @@ -629,12 +668,30 @@ TEST_P(AckHandlersTest, AckPacketNumDoesNotExist) { PacketNum packetNum1 = 9; auto regularPacket1 = createNewPacket(packetNum1, GetParam()); conn.outstandings.packets.emplace_back( - std::move(regularPacket1), Clock::now(), 0, false, 0, 0, 0, LossState()); + std::move(regularPacket1), + Clock::now(), + 0, + 0, + false, + 0, + 0, + 0, + 0, + LossState()); PacketNum packetNum2 = 10; auto regularPacket2 = createNewPacket(packetNum2, GetParam()); conn.outstandings.packets.emplace_back( - std::move(regularPacket2), Clock::now(), 0, false, 0, 0, 0, LossState()); + std::move(regularPacket2), + Clock::now(), + 0, + 0, + false, + 0, + 0, + 0, + 0, + LossState()); // Ack a packet one higher than the packet so that we don't trigger reordering // threshold. @@ -666,10 +723,12 @@ TEST_P(AckHandlersTest, TestHandshakeCounterUpdate) { std::move(regularPacket), Clock::now(), 0, + 0, packetNum % 2 && GetParam() != PacketNumberSpace::AppData, packetNum / 2, 0, 0, + 0, LossState()); if (GetParam() == PacketNumberSpace::Initial) { conn.outstandings.initialPacketsCount += packetNum % 2; @@ -753,7 +812,16 @@ TEST_P(AckHandlersTest, NoSkipAckVisitor) { WriteStreamFrame frame(0, 0, 0, true); regularPacket.frames.emplace_back(std::move(frame)); conn.outstandings.packets.emplace_back(OutstandingPacket( - std::move(regularPacket), Clock::now(), 1, false, 1, 0, 0, LossState())); + std::move(regularPacket), + Clock::now(), + 1, + 0, + false, + 1, + 0, + 0, + 0, + LossState())); ReadAckFrame ackFrame; ackFrame.largestAcked = 0; ackFrame.ackBlocks.emplace_back(0, 0); @@ -795,7 +863,16 @@ TEST_P(AckHandlersTest, SkipAckVisitor) { WriteStreamFrame frame(0, 0, 0, true); regularPacket.frames.emplace_back(std::move(frame)); OutstandingPacket outstandingPacket( - std::move(regularPacket), Clock::now(), 1, false, 1, 0, 0, LossState()); + std::move(regularPacket), + Clock::now(), + 1, + 0, + false, + 1, + 0, + 0, + 0, + LossState()); // Give this outstandingPacket an associatedEvent that's not in // outstandings.packetEvents outstandingPacket.associatedEvent.emplace(PacketNumberSpace::AppData, 0); @@ -836,12 +913,30 @@ TEST_P(AckHandlersTest, NoDoubleProcess) { regularPacket2.frames.push_back(frame); OutstandingPacket outstandingPacket1( - std::move(regularPacket1), Clock::now(), 1, false, 1, 0, 0, LossState()); + std::move(regularPacket1), + Clock::now(), + 1, + 0, + false, + 1, + 0, + 0, + 0, + LossState()); outstandingPacket1.associatedEvent.emplace( PacketNumberSpace::AppData, packetNum1); OutstandingPacket outstandingPacket2( - std::move(regularPacket2), Clock::now(), 1, false, 1, 0, 0, LossState()); + std::move(regularPacket2), + Clock::now(), + 1, + 0, + false, + 1, + 0, + 0, + 0, + LossState()); // The seconds packet has the same PacketEvent outstandingPacket2.associatedEvent.emplace( PacketNumberSpace::AppData, packetNum1); @@ -898,7 +993,16 @@ TEST_P(AckHandlersTest, ClonedPacketsCounter) { auto regularPacket1 = createNewPacket(packetNum1, GetParam()); regularPacket1.frames.push_back(frame); OutstandingPacket outstandingPacket1( - std::move(regularPacket1), Clock::now(), 1, false, 1, 0, 0, LossState()); + std::move(regularPacket1), + Clock::now(), + 1, + 0, + false, + 1, + 0, + 0, + 0, + LossState()); outstandingPacket1.associatedEvent.emplace( PacketNumberSpace::AppData, packetNum1); @@ -907,7 +1011,16 @@ TEST_P(AckHandlersTest, ClonedPacketsCounter) { auto regularPacket2 = createNewPacket(packetNum2, GetParam()); regularPacket2.frames.push_back(frame); OutstandingPacket outstandingPacket2( - std::move(regularPacket2), Clock::now(), 1, false, 1, 0, 0, LossState()); + std::move(regularPacket2), + Clock::now(), + 1, + 0, + false, + 1, + 0, + 0, + 0, + LossState()); conn.outstandings.packets.push_back(std::move(outstandingPacket1)); conn.outstandings.packets.push_back(std::move(outstandingPacket2)); @@ -946,7 +1059,16 @@ TEST_P(AckHandlersTest, UpdateMaxAckDelay) { auto regularPacket = createNewPacket(packetNum, GetParam()); auto sentTime = Clock::now(); conn.outstandings.packets.emplace_back(OutstandingPacket( - std::move(regularPacket), sentTime, 1, false, 1, 0, 0, LossState())); + std::move(regularPacket), + sentTime, + 1, + 0, + false, + 1, + 0, + 0, + 0, + LossState())); ReadAckFrame ackFrame; // ackDelay has no effect on mrtt @@ -1001,10 +1123,12 @@ TEST_P(AckHandlersTest, AckNotOutstandingButLoss) { std::move(regularPacket), Clock::now() - delayUntilLost - 20ms, 1, + 0, false, 1, 0, 0, + 0, LossState()); conn.outstandings.packets.push_back(std::move(outstandingPacket)); conn.outstandings.clonedPacketsCount++; @@ -1039,7 +1163,9 @@ TEST_P(AckHandlersTest, UpdatePendingAckStates) { FizzServerQuicHandshakeContext::Builder().build()); conn.congestionController = nullptr; conn.lossState.totalBytesSent = 2468; + conn.lossState.totalBodyBytesSent = 2000; conn.lossState.totalBytesAcked = 1357; + conn.lossState.totalBodyBytesAcked = 1000; PacketNum packetNum = 0; auto regularPacket = createNewPacket(packetNum, GetParam()); auto sentTime = Clock::now() - 1500ms; @@ -1047,12 +1173,15 @@ TEST_P(AckHandlersTest, UpdatePendingAckStates) { std::move(regularPacket), sentTime, 111, + 100, false, conn.lossState.totalBytesSent + 111, + conn.lossState.totalBodyBytesSent + 100, 0, 0, LossState())); conn.lossState.totalBytesSent += 111; + conn.lossState.totalBodyBytesSent += 100; ReadAckFrame ackFrame; ackFrame.largestAcked = 0; @@ -1071,6 +1200,7 @@ TEST_P(AckHandlersTest, UpdatePendingAckStates) { EXPECT_EQ(sentTime, *conn.lossState.lastAckedPacketSentTime); EXPECT_EQ(receiveTime, *conn.lossState.lastAckedTime); EXPECT_EQ(111 + 1357, conn.lossState.totalBytesAcked); + EXPECT_EQ(100 + 1000, conn.lossState.totalBodyBytesAcked); } TEST_P(AckHandlersTest, AckEventCreation) { @@ -1093,10 +1223,12 @@ TEST_P(AckHandlersTest, AckEventCreation) { std::move(regularPacket), largestSentTime, 1, + 0, false /* handshake */, packetNum, 0, 0, + 0, LossState()); sentPacket.isAppLimited = (packetNum % 2); conn.outstandings.packets.emplace_back(sentPacket); @@ -1150,8 +1282,10 @@ TEST_P(AckHandlersTest, ImplictAckEventCreation) { std::move(regularPacket), largestSentTime, 1, + 0, false /* handshake */, packetNum, + 0, packetNum + 1, 0, LossState()); @@ -1217,8 +1351,10 @@ TEST_P(AckHandlersTest, TestRTTPacketObserverCallback) { std::move(regularPacket), sentTime, 1, + 0, false /* handshake */, packetNum, + 0, packetNum + 1, 0, LossState()); diff --git a/quic/state/test/QuicStateFunctionsTest.cpp b/quic/state/test/QuicStateFunctionsTest.cpp index b9ac82fe8..9a78ce195 100644 --- a/quic/state/test/QuicStateFunctionsTest.cpp +++ b/quic/state/test/QuicStateFunctionsTest.cpp @@ -594,57 +594,97 @@ TEST_F(QuicStateFunctionsTest, GetOutstandingPackets) { makeTestLongPacket(LongHeader::Types::Initial), Clock::now(), 135, + 0, false, 0, 0, 0, + 0, LossState()); conn.outstandings.packets.emplace_back( makeTestLongPacket(LongHeader::Types::Handshake), Clock::now(), 1217, + 0, false, 0, 0, 0, + 0, LossState()); conn.outstandings.packets.emplace_back( - makeTestShortPacket(), Clock::now(), 5556, false, 0, 0, 0, LossState()); + makeTestShortPacket(), + Clock::now(), + 5556, + 5000, + false, + 0, + 0, + 0, + 0, + LossState()); conn.outstandings.packets.emplace_back( makeTestLongPacket(LongHeader::Types::Initial), Clock::now(), 56, + 0, false, 0, 0, 0, + 0, LossState()); conn.outstandings.packets.emplace_back( - makeTestShortPacket(), Clock::now(), 6665, false, 0, 0, 0, LossState()); + makeTestShortPacket(), + Clock::now(), + 6665, + 6000, + false, + 0, + 0, + 0, + 0, + LossState()); EXPECT_EQ( 135, getFirstOutstandingPacket(conn, PacketNumberSpace::Initial) ->metadata.encodedSize); + EXPECT_EQ( + 0, + getFirstOutstandingPacket(conn, PacketNumberSpace::Initial) + ->metadata.encodedBodySize); EXPECT_EQ( 56, getLastOutstandingPacket(conn, PacketNumberSpace::Initial) ->metadata.encodedSize); EXPECT_EQ( - 1217, - getFirstOutstandingPacket(conn, PacketNumberSpace::Handshake) - ->metadata.encodedSize); + 0, + getLastOutstandingPacket(conn, PacketNumberSpace::Initial) + ->metadata.encodedBodySize); EXPECT_EQ( 1217, getFirstOutstandingPacket(conn, PacketNumberSpace::Handshake) ->metadata.encodedSize); + EXPECT_EQ( + 0, + getFirstOutstandingPacket(conn, PacketNumberSpace::Handshake) + ->metadata.encodedBodySize); EXPECT_EQ( 5556, getFirstOutstandingPacket(conn, PacketNumberSpace::AppData) ->metadata.encodedSize); + EXPECT_EQ( + 5000, + getFirstOutstandingPacket(conn, PacketNumberSpace::AppData) + ->metadata.encodedBodySize); EXPECT_EQ( 6665, getLastOutstandingPacket(conn, PacketNumberSpace::AppData) ->metadata.encodedSize); + EXPECT_EQ( + 6000, + getLastOutstandingPacket(conn, PacketNumberSpace::AppData) + ->metadata.encodedBodySize); } TEST_F(QuicStateFunctionsTest, UpdateLargestReceivePacketsAtLatCloseSent) { diff --git a/quic/state/test/StateDataTest.cpp b/quic/state/test/StateDataTest.cpp index a7bcf41e5..ff6cc714f 100644 --- a/quic/state/test/StateDataTest.cpp +++ b/quic/state/test/StateDataTest.cpp @@ -37,7 +37,7 @@ TEST_F(StateDataTest, SingleLostPacketEvent) { 100, kVersion)); OutstandingPacket outstandingPacket( - packet, Clock::now(), 1234, false, 1234, 0, 0, LossState()); + packet, Clock::now(), 1234, 0, false, 1234, 0, 0, 0, LossState()); CongestionController::LossEvent loss; loss.addLostPacket(outstandingPacket); EXPECT_EQ(1234, loss.lostBytes); @@ -52,7 +52,7 @@ TEST_F(StateDataTest, MultipleLostPacketsEvent) { 100, kVersion)); OutstandingPacket outstandingPacket1( - packet1, Clock::now(), 1234, false, 1234, 0, 0, LossState()); + packet1, Clock::now(), 1234, 0, false, 1234, 0, 0, 0, LossState()); RegularQuicWritePacket packet2(LongHeader( LongHeader::Types::Initial, @@ -61,7 +61,7 @@ TEST_F(StateDataTest, MultipleLostPacketsEvent) { 110, kVersion)); OutstandingPacket outstandingPacket2( - packet2, Clock::now(), 1357, false, 1357, 0, 0, LossState()); + packet2, Clock::now(), 1357, 0, false, 1357, 0, 0, 0, LossState()); CongestionController::LossEvent loss; loss.addLostPacket(outstandingPacket1);